-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.go
53 lines (42 loc) · 1.01 KB
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"fmt"
"log"
"time"
"github.com/gin-gonic/gin"
// TODO: import as directed in the install flow
"github.com/newrelic/go-agent/v3/newrelic"
// TODO: import for gin instrumentation
"github.com/newrelic/go-agent/v3/integrations/nrgin"
)
func main() {
go client()
//TODO: paste your creds for the app
app, err := newrelic.NewApplication(
newrelic.ConfigAppName("<APP NAME>"),
newrelic.ConfigLicense("xxxxxxxxxxxxxxxxxxxxxxxxxxxx"),
newrelic.ConfigAppLogForwardingEnabled(true),
)
if err != nil {
log.Panic(err)
}
transactions := make(chan string)
go func() {
for {
// Generate a new transaction.
transaction := fmt.Sprintf("Transaction generated at %s", time.Now().Format(time.RFC3339))
transactions <- transaction
time.Sleep(time.Second)
}
}()
// Create a Gin router.
r := gin.Default()
r.Use(nrgin.Middleware(app))
r.GET("/transaction", func(c *gin.Context) {
transaction := <-transactions
c.JSON(200, gin.H{
"transaction": transaction,
})
})
r.Run()
}