-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
executable file
·43 lines (39 loc) · 1.11 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
// Code generated by hertz generator.
package main
import (
"github.com/cloudwego/hertz/pkg/app/server"
"github.com/cloudwego/hertz/pkg/common/hlog"
"github.com/cloudwego/kitex/pkg/klog"
"github.com/hcdoit/tiktok/cmd/api/biz/mw"
"github.com/hcdoit/tiktok/cmd/api/biz/rpc"
"github.com/hcdoit/tiktok/pkg/consts"
hertzlogrus "github.com/hertz-contrib/obs-opentelemetry/logging/logrus"
"github.com/hertz-contrib/obs-opentelemetry/tracing"
"github.com/hertz-contrib/pprof"
kitexlogrus "github.com/kitex-contrib/obs-opentelemetry/logging/logrus"
)
func Init() {
rpc.Init()
mw.InitCheckToken()
// hlog init
hlog.SetLogger(hertzlogrus.NewLogger())
hlog.SetLevel(consts.HLoggerLevel)
klog.SetLogger(kitexlogrus.NewLogger())
klog.SetLevel(consts.KLoggerLevel)
}
func main() {
Init()
tracer, cfg := tracing.NewServerTracer()
h := server.New(
server.WithHostPorts(":8080"),
server.WithMaxRequestBodySize(200*1024*1024),
server.WithHandleMethodNotAllowed(true), // coordinate with NoMethod
tracer,
)
// use pprof mw
pprof.Register(h)
// use otel mw
h.Use(tracing.ServerMiddleware(cfg))
register(h)
h.Spin()
}