-
Notifications
You must be signed in to change notification settings - Fork 14
/
main.go
86 lines (72 loc) · 2.5 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"context"
"toktik/constant/config"
"toktik/service/web/auth"
"toktik/service/web/comment"
"toktik/service/web/favorite"
"toktik/service/web/feed"
"toktik/service/web/mw"
"toktik/service/web/publish"
"toktik/service/web/relation"
"toktik/service/web/user"
"toktik/service/web/wechat"
"github.com/cloudwego/hertz/pkg/app/server"
"github.com/hertz-contrib/gzip"
"github.com/hertz-contrib/obs-opentelemetry/provider"
"github.com/hertz-contrib/obs-opentelemetry/tracing"
"github.com/hertz-contrib/pprof"
"github.com/hertz-contrib/swagger"
swaggerFiles "github.com/swaggo/files"
)
func main() {
p := provider.NewOpenTelemetryProvider(
provider.WithServiceName(config.WebServiceName),
provider.WithExportEndpoint(config.EnvConfig.EXPORT_ENDPOINT),
provider.WithInsecure(),
)
defer p.Shutdown(context.Background())
tracer, cfg := tracing.NewServerTracer()
h := server.Default(
server.WithHostPorts(config.WebServiceAddr),
server.WithMaxRequestBodySize(config.EnvConfig.MAX_REQUEST_BODY_SIZE),
tracer,
)
h.Use(gzip.Gzip(gzip.DefaultCompression))
h.Use(mw.AuthMiddleware())
h.Use(tracing.ServerMiddleware(cfg))
pprof.Register(h)
douyin := h.Group("/douyin")
// feed service
douyin.GET("/feed", feed.Action)
// user service
userGroup := douyin.Group("/user")
userGroup.POST("/register/", auth.Register)
userGroup.POST("/login/", auth.Login)
userGroup.GET("/", user.GetUserInfo)
// publish service
publishGroup := douyin.Group("/publish")
publishGroup.POST("/action/", publish.Action)
publishGroup.GET("/list", publish.List)
// favorite service
favoriteGroup := douyin.Group("/favorite")
favoriteGroup.POST("/action/", favorite.Action)
favoriteGroup.GET("/list/", favorite.List)
// comment service
commentGroup := douyin.Group("/comment")
commentGroup.POST("/action/", comment.Action)
commentGroup.GET("/list/", comment.List)
// relation service
relationGroup := douyin.Group("/relation")
relationGroup.POST("/action/", relation.RelationAction)
relationGroup.GET("/follow/list/", relation.GetFollowList)
relationGroup.GET("/follower/list/", relation.GetFollowerList)
relationGroup.GET("/friend/list/", relation.GetFriendList)
// message service
messageGroup := douyin.Group("/message")
messageGroup.POST("/action/", wechat.MessageAction)
messageGroup.GET("/chat/", wechat.MessageChat)
url := swagger.URL("http://localhost:8080/swagger/doc.json") // The url pointing to API definition
h.GET("/swagger/*any", swagger.WrapHandler(swaggerFiles.Handler, url))
h.Spin()
}