-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.go
60 lines (54 loc) · 1.81 KB
/
init.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
54
55
56
57
58
59
60
package main
import (
"log"
"time"
"github.com/PBH-BTN/trunker/biz/config"
"github.com/PBH-BTN/trunker/biz/services/peer"
"github.com/PBH-BTN/trunker/biz/services/rpc"
"github.com/PBH-BTN/trunker/biz/services/udp_server"
"github.com/PBH-BTN/trunker/service/metrics"
"github.com/PBH-BTN/trunker/service/mq/producer"
"github.com/cloudwego/hertz/pkg/app/server"
hertzConfig "github.com/cloudwego/hertz/pkg/common/config"
"github.com/cloudwego/hertz/pkg/common/hlog"
prometheus "github.com/hertz-contrib/monitor-prometheus"
"github.com/panjf2000/gnet/v2"
)
func Init() {
config.Init()
if config.AppConfig.Tracker.EnableEventProducer {
producer.Init()
}
metrics.Init()
//cache.Init()
peer.InitPeerManager()
if config.AppConfig.Tracker.UDPServer.Enable {
go initUDPServer()
}
if config.AppConfig.Tracker.RPC.EnableServer {
go rpc.StartRPCServer(config.AppConfig.Tracker.RPC.HostPorts)
}
}
func getServerOption() []hertzConfig.Option {
options := []hertzConfig.Option{
server.WithHostPorts(config.AppConfig.Tracker.HostPorts),
server.WithExitWaitTime(time.Minute),
}
if config.AppConfig.Tracker.EnableMetrics {
options = append(options, server.WithTracer(
prometheus.NewServerTracer(config.AppConfig.Tracker.MetricsHostPorts, "/metrics",
prometheus.WithDefaultServerMux(true),
prometheus.WithEnableGoCollector(true),
prometheus.WithRegistry(metrics.GetRegistry()),
),
))
hlog.Info("metrics is listen at ", config.AppConfig.Tracker.MetricsHostPorts)
}
if config.AppConfig.Tracker.UseUnixSocket {
options = append(options, server.WithNetwork("unix"))
}
return options
}
func initUDPServer() {
log.Fatal(gnet.Run(udp_server.NewUDPServer(), "udp://"+config.AppConfig.Tracker.UDPServer.HostPorts, gnet.WithMulticore(true), gnet.WithTicker(true), gnet.WithLogger(hlog.DefaultLogger())))
}