-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
49 lines (40 loc) · 1019 Bytes
/
main.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
package main
import (
"fmt"
"log"
"os"
"github.com/fasthttp/router"
"github.com/valyala/fasthttp"
gcrwavefront "github.com/retgits/gcr-wavefront"
)
func Index(ctx *fasthttp.RequestCtx) {
fmt.Fprint(ctx, "Welcome!\n")
}
func Hello(ctx *fasthttp.RequestCtx) {
fmt.Fprintf(ctx, "hello, %s!\n", ctx.UserValue("name"))
}
func main() {
log.Print("Hello world sample started.")
cfg := gcrwavefront.WavefrontConfig{
Server: gcrwavefront.DebugServerName,
Token: "my-api-key",
BatchSize: 10000,
MaxBufferSize: 50000,
FlushInterval: 1,
Source: "my-app",
MetricPrefix: "my.awesome.app",
PointTags: make(map[string]string),
}
err := cfg.ConfigureSender()
if err != nil {
panic(err)
}
router := router.New()
router.GET("/", cfg.WrapFastHTTPRequest(Index))
router.GET("/hello/:name", cfg.WrapFastHTTPRequest(Hello))
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
log.Fatal(fasthttp.ListenAndServe(fmt.Sprintf(":%s", port), router.Handler))
}