-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
executable file
·57 lines (51 loc) · 1.69 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
54
55
56
57
// Code generated by hertz generator.
package main
import (
"context"
"github.com/CloudStriver/cloudmind-core-api/biz/adaptor"
"github.com/CloudStriver/cloudmind-core-api/provider"
"github.com/CloudStriver/go-pkg/utils/hertz/middleware"
"github.com/CloudStriver/go-pkg/utils/util/log"
"github.com/hertz-contrib/cors"
"github.com/hertz-contrib/obs-opentelemetry/tracing"
"time"
"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"
"go.opentelemetry.io/contrib/propagators/b3"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/propagation"
)
func Init() {
provider.Init()
hlog.SetLogger(log.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(cors.New(cors.Config{
AllowOrigins: []string{"*"},
AllowMethods: []string{"*"},
AllowHeaders: []string{"*"},
ExposeHeaders: []string{"*"},
AllowCredentials: true,
AllowOriginFunc: func(origin string) bool {
return true
}, MaxAge: 24 * time.Hour,
}), 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()
}