@@ -3,9 +3,7 @@ package ServiceV2
33import (
44 "code/Hahachitchat/dataLayer"
55 "code/Hahachitchat/definition"
6- "github.com/chenjiandongx/ginprom"
76 "github.com/gin-gonic/gin"
8- "github.com/prometheus/client_golang/prometheus/promhttp"
97 "os"
108)
119
@@ -36,40 +34,36 @@ func StartService(port string) {
3634 ServiceInit ()
3735
3836 r := gin .Default ()
39- // use prometheus metrics exporter middleware.
40- r .Use (ginprom .PromMiddleware (ginprom .NewDefaultOpts ()))
4137
42- // register the `/metrices` route.
38+ r . Use ( HearsetMiddleWare ())
4339
44- r . GET ( "/metrics " , ginprom . PromHandler ( promhttp . Handler () ))
40+ clientRoute := r . Group ( " " , ClientLogMiddleWare (), ForbiddenMiddleWare ( ))
4541
46- r .Use (HearsetMiddleWare (), ForbiddenMiddleWare ())
42+ clientRoute .GET ("/" , DefaultTest )
43+ clientRoute .GET ("/allpostid" , AllPostId )
44+ clientRoute .GET ("/top-post" , GetTopPost )
45+ clientRoute .GET ("/allcommentid/:post_id" , AllCommentIdByPostId )
46+ clientRoute .GET ("/user/:u_id" , GetUserById )
47+ clientRoute .GET ("/post/:post_id" , GetPostById )
48+ clientRoute .GET ("/comment/:comment_id" , GetCommentById )
49+ clientRoute .GET ("/reply/:reply_id" , GetReplyById )
50+ clientRoute .GET ("/allposthot" , AllPostHot )
51+ clientRoute .GET ("/getimg/:img_id" , GetImg )
52+ clientRoute .GET ("/id-by-name/:u_nickname" , GetUidByUserNickname )
4753
48- r .GET ("/" , DefaultTest )
49- r .GET ("/allpostid" , AllPostId )
50- r .GET ("/top-post" , GetTopPost )
51- r .GET ("/allcommentid/:post_id" , AllCommentIdByPostId )
52- r .GET ("/user/:u_id" , GetUserById )
53- r .GET ("/post/:post_id" , GetPostById )
54- r .GET ("/comment/:comment_id" , GetCommentById )
55- r .GET ("/reply/:reply_id" , GetReplyById )
56- r .GET ("/allposthot" , AllPostHot )
57- r .GET ("/getimg/:img_id" , GetImg )
58- r .GET ("/id-by-name/:u_nickname" , GetUidByUserNickname )
59-
60- r .POST ("/register" , Register )
61- r .POST ("/login" , Login )
54+ clientRoute .POST ("/register" , Register )
55+ clientRoute .POST ("/login" , Login )
6256
6357 //可能需要登录态的操作 个人资料(根据用户隐私设置判断是否展示)
64- profileRoute := r .Group ("/profile" , SetSessionMiddleWare ())
58+ profileRoute := clientRoute .Group ("/profile" , SetSessionMiddleWare ())
6559 profileRoute .GET ("/user-saved/:u_id" , GetUserSavedPost )
6660 profileRoute .GET ("/subscriptions/:u_id" , GetSubscriptions )
6761 profileRoute .GET ("/allpostid-by-uid/:u_id" , GetUserAllPostId )
6862 profileRoute .GET ("/allcommentid-by-uid/:u_id" , GetUserAllCommentId )
6963 profileRoute .GET ("/allreplyid-by-uid/:u_id" , GetUserAllReplyId )
7064
7165 // 需要登录态的操作
72- needSessionRoute := r .Group ("" , AuthMiddleWare ())
66+ needSessionRoute := clientRoute .Group ("" , AuthMiddleWare ())
7367
7468 needSessionRoute .GET ("/user_state" , GetUserState )
7569 needSessionRoute .GET ("/ws-connect" , WebSocketConnect )
@@ -100,13 +94,13 @@ func StartService(port string) {
10094 MessageRoute .POST ("/ignore" , IgnoreMessages )
10195
10296 // ------------V2--------------
103- routeV2 := r .Group ("/v2" )
97+ routeV2 := clientRoute .Group ("/v2" )
10498 routeV2 .GET ("/zone/:zone" , AllPostByZone )
10599 routeV2 .GET ("/comment/:comment_id" , GetCommentByIdV2 )
106100 routeV2 .POST ("/posts" , BatchQueryPost )
107101
108102 // 点赞功能
109- voteRoute := r .Group ("/vote" )
103+ voteRoute := clientRoute .Group ("/vote" )
110104 voteRoute .GET ("/post/:post_id" , GetPostVote )
111105 voteRoute .GET ("/comment/:comment_id" , GetCommentVote )
112106 voteRoute .POST ("/post" , AuthMiddleWare (), VotePost )
@@ -117,7 +111,7 @@ func StartService(port string) {
117111 adminRoute .GET ("/users" , GetAllUser )
118112 adminRoute .GET ("/ban-users" , GetBanUser )
119113 adminRoute .POST ("/add-ban-users" , AddBanUser )
120- adminRoute .POST ("/cancel-ban-users" ,CancelBanUser )
114+ adminRoute .POST ("/cancel-ban-users" , CancelBanUser )
121115 adminRoute .GET ("/ban-ips" , GetBanIPs )
122116 adminRoute .POST ("/add-ban-ips" , AddBanIP )
123117 adminRoute .POST ("/cancel-ban-ip" , CancelBanIp )
@@ -127,11 +121,11 @@ func StartService(port string) {
127121 adminRoute .POST ("/delete-reply" , AdminDeleteReplyById )
128122 adminRoute .POST ("/set-top-post" , SetTopPost )
129123 // 审批功能
130- adminRoute .POST ("/set-approval-user" ,SetApprovalUser )
131- adminRoute .GET ("/need-approval-post" ,GetNeedApprovalPost )
132- adminRoute .POST ("/approval-post" ,ApprovalPost )
124+ adminRoute .POST ("/set-approval-user" , SetApprovalUser )
125+ adminRoute .GET ("/need-approval-post" , GetNeedApprovalPost )
126+ adminRoute .POST ("/approval-post" , ApprovalPost )
133127 //日志功能
134-
128+ adminRoute . GET ( "/log-ws-connect" , LogWebSocketConnect )
135129 // 查看统计图
136130 postStatisticsRoute := adminRoute .Group ("/post-statistics" )
137131 postStatisticsRoute .GET ("/line-chart" , PostStatisticsLineChart )
0 commit comments