-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (41 loc) · 1.42 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
// Code generated by hertz generator.
package main
import (
"context"
"github.com/cloudwego/hertz/pkg/app"
"github.com/cloudwego/hertz/pkg/app/middlewares/server/recovery"
"github.com/cloudwego/hertz/pkg/app/server"
"github.com/cloudwego/hertz/pkg/common/hlog"
prometheus "github.com/hertz-contrib/monitor-prometheus"
"github.com/hertz-contrib/obs-opentelemetry/tracing"
"github.com/xh-polaris/gopkg/hertz/middleware"
logx "github.com/xh-polaris/gopkg/util/log"
"github.com/xh-polaris/openapi-core-api/biz/adaptor"
"github.com/xh-polaris/openapi-core-api/biz/infrastructure/util/log"
"github.com/xh-polaris/openapi-core-api/provider"
"go.opentelemetry.io/contrib/propagators/b3"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/propagation"
)
func Init() {
provider.Init()
hlog.SetLogger(logx.NewHlogLogger())
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(b3.New(), propagation.Baggage{}, propagation.TraceContext{}))
}
func main() {
Init()
c := provider.Get().Config
tracer, cfg := tracing.NewServerTracer()
h := server.New(
server.WithHostPorts(c.ListenOn),
server.WithTracer(prometheus.NewServerTracer(":9091", "/server/metrics")),
tracer,
)
h.Use(tracing.ServerMiddleware(cfg), middleware.EnvironmentMiddleware, recovery.Recovery(), func(ctx context.Context, c *app.RequestContext) {
ctx = adaptor.InjectContext(ctx, c)
c.Next(ctx)
})
register(h)
log.Info("server start")
h.Spin()
}