File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change 6
6
"net/http"
7
7
8
8
"github.com/bethanyj28/battlesnek/internal"
9
+ "github.com/newrelic/go-agent/v3/newrelic"
9
10
"github.com/sirupsen/logrus"
10
11
)
11
12
@@ -21,10 +22,25 @@ func (s *server) handleEnd() http.HandlerFunc {
21
22
return
22
23
}
23
24
25
+ if txn := newrelic .FromContext (r .Context ()); nil != txn {
26
+ txn .AddAttribute ("won" , didSnakeWin (state .Board .Snakes , state .You ))
27
+ txn .AddAttribute ("turns" , state .Turn )
28
+ txn .AddAttribute ("game_id" , state .Game .ID )
29
+ }
30
+
24
31
s .logger .WithFields (logrus.Fields {
25
32
"game_state" : fmt .Sprintf ("%+v" , state ),
26
33
}).Info ("END" )
27
34
28
35
w .WriteHeader (http .StatusOK )
29
36
}
30
37
}
38
+
39
+ func didSnakeWin (remainingSnakes []internal.Battlesnake , you internal.Battlesnake ) bool {
40
+ for _ , snake := range remainingSnakes {
41
+ if snake .ID == you .ID {
42
+ return true
43
+ }
44
+ }
45
+ return false
46
+ }
You can’t perform that action at this time.
0 commit comments