-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
executable file
·50 lines (46 loc) · 1.34 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
package main
import (
"context"
"os"
"time"
appConfig "github.com/PBH-BTN/trunker/biz/config"
"github.com/PBH-BTN/trunker/biz/middleware"
"github.com/PBH-BTN/trunker/biz/services/interval"
"github.com/PBH-BTN/trunker/biz/services/peer"
"github.com/PBH-BTN/trunker/service/metrics"
"github.com/cloudwego/hertz/pkg/app/server"
"github.com/cloudwego/hertz/pkg/common/config"
"github.com/cloudwego/hertz/pkg/common/hlog"
prometheus "github.com/hertz-contrib/monitor-prometheus"
"github.com/hertz-contrib/pprof"
)
func main() {
if os.Getenv("RUN_ENV") == "prod" {
hlog.SetLevel(hlog.LevelInfo)
}
Init()
options := []config.Option{
server.WithTracer(
prometheus.NewServerTracer(":9091", "/metrics",
prometheus.WithDefaultServerMux(true),
prometheus.WithEnableGoCollector(true),
prometheus.WithRegistry(metrics.GetRegistry()),
),
),
server.WithHostPorts(appConfig.AppConfig.Tracker.HostPorts),
server.WithExitWaitTime(time.Minute),
}
if appConfig.AppConfig.Tracker.UseUnixSocket {
options = append(options, server.WithNetwork("unix"))
}
h := server.Default(options...)
pprof.Register(h)
register(h)
h.Use(middleware.LogSlowQuery)
h.Engine.OnShutdown = append(h.Engine.OnShutdown, func(_ context.Context) {
// here save current data
peer.GetPeerManager().StoreToPersist()
})
interval.StartIntervalTask()
h.Spin()
}