-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (44 loc) · 1.06 KB
/
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
50
51
52
53
package main
import (
"fmt"
"github.com/getsentry/sentry-go"
log "github.com/sirupsen/logrus"
"net/http"
"os"
_ "embed"
"github.com/slok/go-http-metrics/middleware"
"github.com/slok/go-http-metrics/middleware/std"
metrics "github.com/slok/go-http-metrics/metrics/prometheus"
)
func main() {
sentryDsn := os.Getenv("SENTRY_DSN")
if sentryDsn != "" {
err := sentry.Init(sentry.ClientOptions{
Dsn: sentryDsn,
TracesSampleRate: 0.1,
})
if err != nil {
log.Fatalf("sentry.Init: %s", err)
}
} else {
log.Warn("SENTRY_DSN was not provided. Running without sentry.")
}
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
router, err := getRouter(true)
if err != nil {
log.Fatal(err)
}
mdlw := middleware.New(middleware.Config{
Recorder: metrics.NewRecorder(metrics.Config{
Prefix: "shadowtest",
}),
})
routerWithMetrics := std.Handler("", mdlw, router)
log.Infof("Starting server at port %s\n", port)
if err := http.ListenAndServe(fmt.Sprintf(":%s", port), routerWithMetrics); err != nil {
log.Fatal(err)
}
}