作者 tangxvhui
@@ -12,6 +12,7 @@ info( @@ -12,6 +12,7 @@ info(
12 @server( 12 @server(
13 prefix: v1/mini 13 prefix: v1/mini
14 group: article 14 group: article
  15 + middleware: LogRequest
15 jwt: MiniAuth 16 jwt: MiniAuth
16 ) 17 )
17 service Core { 18 service Core {
@@ -86,7 +87,7 @@ service Core { @@ -86,7 +87,7 @@ service Core {
86 @server( 87 @server(
87 prefix: v1/system 88 prefix: v1/system
88 group: article 89 group: article
89 - middleware: LoginStatusCheck 90 + middleware: LoginStatusCheck,LogRequest
90 jwt: SystemAuth 91 jwt: SystemAuth
91 ) 92 )
92 service Core { 93 service Core {
@@ -11,7 +11,7 @@ info( @@ -11,7 +11,7 @@ info(
11 @server( 11 @server(
12 prefix: v1/system 12 prefix: v1/system
13 group: tags 13 group: tags
14 - middleware: LoginStatusCheck 14 + middleware: LoginStatusCheck,LogRequest
15 jwt: SystemAuth 15 jwt: SystemAuth
16 ) 16 )
17 service Core { 17 service Core {
@@ -12,6 +12,7 @@ info( @@ -12,6 +12,7 @@ info(
12 @server( 12 @server(
13 prefix: v1/mini 13 prefix: v1/mini
14 group: comment 14 group: comment
  15 + middleware: LogRequest
15 jwt: MiniAuth 16 jwt: MiniAuth
16 ) 17 )
17 service Core { 18 service Core {
@@ -44,7 +45,7 @@ service Core { @@ -44,7 +45,7 @@ service Core {
44 @server( 45 @server(
45 prefix: v1/system 46 prefix: v1/system
46 group: comment 47 group: comment
47 - middleware: LoginStatusCheck 48 + middleware: LoginStatusCheck,LogRequest
48 jwt: SystemAuth 49 jwt: SystemAuth
49 ) 50 )
50 service Core { 51 service Core {
@@ -12,6 +12,7 @@ info( @@ -12,6 +12,7 @@ info(
12 @server( 12 @server(
13 prefix: v1 13 prefix: v1
14 group: company 14 group: company
  15 + middleware: LogRequest
15 ) 16 )
16 service Core { 17 service Core {
17 @doc "公司搜索(公开的)" 18 @doc "公司搜索(公开的)"
@@ -23,6 +24,7 @@ service Core { @@ -23,6 +24,7 @@ service Core {
23 @server( 24 @server(
24 prefix: v1 25 prefix: v1
25 group: company 26 group: company
  27 + middleware: LogRequest
26 jwt : MiniAuth 28 jwt : MiniAuth
27 ) 29 )
28 service Core { 30 service Core {
@@ -31,11 +33,11 @@ service Core { @@ -31,11 +33,11 @@ service Core {
31 post /mini/company/search-joined(CompanySearchRequest) returns (CompanySearchResponse) 33 post /mini/company/search-joined(CompanySearchRequest) returns (CompanySearchResponse)
32 } 34 }
33 35
34 -// 小程序接口 36 +// 后台接口
35 @server( 37 @server(
36 prefix: v1 38 prefix: v1
37 group: company 39 group: company
38 - middleware: LoginStatusCheck 40 + middleware: LoginStatusCheck,LogRequest
39 jwt : SystemAuth 41 jwt : SystemAuth
40 ) 42 )
41 service Core { 43 service Core {
@@ -11,7 +11,7 @@ info( @@ -11,7 +11,7 @@ info(
11 @server( 11 @server(
12 prefix: v1 12 prefix: v1
13 group: department 13 group: department
14 - middleware: LoginStatusCheck 14 + middleware: LoginStatusCheck,LogRequest
15 jwt: SystemAuth 15 jwt: SystemAuth
16 ) 16 )
17 service Core { 17 service Core {
@@ -11,6 +11,7 @@ info( @@ -11,6 +11,7 @@ info(
11 @server( 11 @server(
12 prefix: v1 12 prefix: v1
13 group: message 13 group: message
  14 + middleware: LogRequest
14 jwt: MiniAuth 15 jwt: MiniAuth
15 ) 16 )
16 service Core { 17 service Core {
@@ -11,7 +11,7 @@ info( @@ -11,7 +11,7 @@ info(
11 @server( 11 @server(
12 prefix: v1 12 prefix: v1
13 group: role 13 group: role
14 - middleware: LoginStatusCheck 14 + middleware: LoginStatusCheck,LogRequest
15 jwt: SystemAuth 15 jwt: SystemAuth
16 ) 16 )
17 service Core { 17 service Core {
@@ -24,6 +24,7 @@ service Core { @@ -24,6 +24,7 @@ service Core {
24 @server( 24 @server(
25 prefix: v1 25 prefix: v1
26 group: user 26 group: user
  27 + middleware: LogRequest
27 jwt: MiniAuth 28 jwt: MiniAuth
28 ) 29 )
29 service Core { 30 service Core {
@@ -255,7 +256,7 @@ type ( @@ -255,7 +256,7 @@ type (
255 @server( 256 @server(
256 prefix: v1 257 prefix: v1
257 group: user 258 group: user
258 - middleware: LoginStatusCheck 259 + middleware: LoginStatusCheck,LogRequest
259 jwt: SystemAuth 260 jwt: SystemAuth
260 ) 261 )
261 service Core { 262 service Core {
@@ -6,6 +6,8 @@ Migrate: false @@ -6,6 +6,8 @@ Migrate: false
6 Timeout: 30000 6 Timeout: 30000
7 # CertFile: ./key/fjmaimaimai.com_bundle.crt 7 # CertFile: ./key/fjmaimaimai.com_bundle.crt
8 # KeyFile: ./key/fjmaimaimai.com.key 8 # KeyFile: ./key/fjmaimaimai.com.key
  9 +LogRequest: true # 记录详细请求日志
  10 +
9 Log: 11 Log:
10 #Mode: file 12 #Mode: file
11 Encoding: plain 13 Encoding: plain
@@ -16,6 +16,7 @@ type Config struct { @@ -16,6 +16,7 @@ type Config struct {
16 Migrate bool `json:",optional,default=true"` 16 Migrate bool `json:",optional,default=true"`
17 ApiAuth ApiService 17 ApiAuth ApiService
18 DebugSmsCode string `json:",optional,default=999512"` 18 DebugSmsCode string `json:",optional,default=999512"`
  19 + LogRequest bool `json:",optional,default=true"`
19 } 20 }
20 21
21 type ApiService struct { 22 type ApiService struct {
@@ -36,45 +36,48 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { @@ -36,45 +36,48 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
36 ) 36 )
37 37
38 server.AddRoutes( 38 server.AddRoutes(
39 - []rest.Route{  
40 - {  
41 - Method: http.MethodPost,  
42 - Path: "/article_comment",  
43 - Handler: comment.MiniCreateArticleCommentHandler(serverCtx),  
44 - },  
45 - {  
46 - Method: http.MethodPost,  
47 - Path: "/article_comment/list",  
48 - Handler: comment.MiniListArticleCommentHandler(serverCtx),  
49 - },  
50 - {  
51 - Method: http.MethodPost,  
52 - Path: "/article_comment/top5",  
53 - Handler: comment.MiniTop5ArticleCommentHandler(serverCtx),  
54 - },  
55 - {  
56 - Method: http.MethodGet,  
57 - Path: "/article_comment/:id",  
58 - Handler: comment.MiniGetArticleCommentHandler(serverCtx),  
59 - },  
60 - {  
61 - Method: http.MethodDelete,  
62 - Path: "/article_comment/:id",  
63 - Handler: comment.MiniDeleteArticleCommentHandler(serverCtx),  
64 - },  
65 - {  
66 - Method: http.MethodPost,  
67 - Path: "/article_comment/at_who/list",  
68 - Handler: comment.MiniArticleCommentAtWhoHandler(serverCtx),  
69 - },  
70 - }, 39 + rest.WithMiddlewares(
  40 + []rest.Middleware{serverCtx.LogRequest},
  41 + []rest.Route{
  42 + {
  43 + Method: http.MethodPost,
  44 + Path: "/article_comment",
  45 + Handler: comment.MiniCreateArticleCommentHandler(serverCtx),
  46 + },
  47 + {
  48 + Method: http.MethodPost,
  49 + Path: "/article_comment/list",
  50 + Handler: comment.MiniListArticleCommentHandler(serverCtx),
  51 + },
  52 + {
  53 + Method: http.MethodPost,
  54 + Path: "/article_comment/top5",
  55 + Handler: comment.MiniTop5ArticleCommentHandler(serverCtx),
  56 + },
  57 + {
  58 + Method: http.MethodGet,
  59 + Path: "/article_comment/:id",
  60 + Handler: comment.MiniGetArticleCommentHandler(serverCtx),
  61 + },
  62 + {
  63 + Method: http.MethodDelete,
  64 + Path: "/article_comment/:id",
  65 + Handler: comment.MiniDeleteArticleCommentHandler(serverCtx),
  66 + },
  67 + {
  68 + Method: http.MethodPost,
  69 + Path: "/article_comment/at_who/list",
  70 + Handler: comment.MiniArticleCommentAtWhoHandler(serverCtx),
  71 + },
  72 + }...,
  73 + ),
71 rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret), 74 rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
72 rest.WithPrefix("/v1/mini"), 75 rest.WithPrefix("/v1/mini"),
73 ) 76 )
74 77
75 server.AddRoutes( 78 server.AddRoutes(
76 rest.WithMiddlewares( 79 rest.WithMiddlewares(
77 - []rest.Middleware{serverCtx.LoginStatusCheck}, 80 + []rest.Middleware{serverCtx.LoginStatusCheck, serverCtx.LogRequest},
78 []rest.Route{ 81 []rest.Route{
79 { 82 {
80 Method: http.MethodPost, 83 Method: http.MethodPost,
@@ -113,30 +116,33 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { @@ -113,30 +116,33 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
113 ) 116 )
114 117
115 server.AddRoutes( 118 server.AddRoutes(
116 - []rest.Route{  
117 - {  
118 - Method: http.MethodPost,  
119 - Path: "/mini/message/system",  
120 - Handler: message.MiniSystemHandler(serverCtx),  
121 - },  
122 - {  
123 - Method: http.MethodPost,  
124 - Path: "/mini/message/comment",  
125 - Handler: message.MiniCommentHandler(serverCtx),  
126 - },  
127 - {  
128 - Method: http.MethodPost,  
129 - Path: "/mini/message/like",  
130 - Handler: message.MiniLikeHandler(serverCtx),  
131 - },  
132 - }, 119 + rest.WithMiddlewares(
  120 + []rest.Middleware{serverCtx.LogRequest},
  121 + []rest.Route{
  122 + {
  123 + Method: http.MethodPost,
  124 + Path: "/mini/message/system",
  125 + Handler: message.MiniSystemHandler(serverCtx),
  126 + },
  127 + {
  128 + Method: http.MethodPost,
  129 + Path: "/mini/message/comment",
  130 + Handler: message.MiniCommentHandler(serverCtx),
  131 + },
  132 + {
  133 + Method: http.MethodPost,
  134 + Path: "/mini/message/like",
  135 + Handler: message.MiniLikeHandler(serverCtx),
  136 + },
  137 + }...,
  138 + ),
133 rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret), 139 rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
134 rest.WithPrefix("/v1"), 140 rest.WithPrefix("/v1"),
135 ) 141 )
136 142
137 server.AddRoutes( 143 server.AddRoutes(
138 rest.WithMiddlewares( 144 rest.WithMiddlewares(
139 - []rest.Middleware{serverCtx.LoginStatusCheck}, 145 + []rest.Middleware{serverCtx.LoginStatusCheck, serverCtx.LogRequest},
140 []rest.Route{ 146 []rest.Route{
141 { 147 {
142 Method: http.MethodPost, 148 Method: http.MethodPost,
@@ -191,90 +197,93 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { @@ -191,90 +197,93 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
191 ) 197 )
192 198
193 server.AddRoutes( 199 server.AddRoutes(
194 - []rest.Route{  
195 - {  
196 - Method: http.MethodPost,  
197 - Path: "/mini/user/switch_account",  
198 - Handler: user.MiniUserSwitchAccountHandler(serverCtx),  
199 - },  
200 - {  
201 - Method: http.MethodPost,  
202 - Path: "/mini/user/info",  
203 - Handler: user.MiniUserInfoHandler(serverCtx),  
204 - },  
205 - {  
206 - Method: http.MethodPost,  
207 - Path: "/mini/user/statistics",  
208 - Handler: user.MiniUserStatisticsHandler(serverCtx),  
209 - },  
210 - {  
211 - Method: http.MethodPost,  
212 - Path: "/mini/user/audit_list",  
213 - Handler: user.MiniUserAuditListHandler(serverCtx),  
214 - },  
215 - {  
216 - Method: http.MethodPost,  
217 - Path: "/mini/user/audit",  
218 - Handler: user.MiniUserAuditHandler(serverCtx),  
219 - },  
220 - {  
221 - Method: http.MethodPost,  
222 - Path: "/mini/user/department_users",  
223 - Handler: user.MiniUserDepartmentUsersHandler(serverCtx),  
224 - },  
225 - {  
226 - Method: http.MethodPost,  
227 - Path: "/mini/user/user_list",  
228 - Handler: user.MiniUsersListHandler(serverCtx),  
229 - },  
230 - {  
231 - Method: http.MethodPost,  
232 - Path: "/mini/user/news",  
233 - Handler: user.MiniUserNewsHandler(serverCtx),  
234 - },  
235 - {  
236 - Method: http.MethodPost,  
237 - Path: "/mini/user/follower",  
238 - Handler: user.MiniUserFollowerHandler(serverCtx),  
239 - },  
240 - {  
241 - Method: http.MethodPost,  
242 - Path: "/mini/user/following",  
243 - Handler: user.MiniUserFollowingHandler(serverCtx),  
244 - },  
245 - {  
246 - Method: http.MethodPost,  
247 - Path: "/mini/user/following/latest_unread_list",  
248 - Handler: user.MiniUserFollowingLatestUnreadListHandler(serverCtx),  
249 - },  
250 - {  
251 - Method: http.MethodPost,  
252 - Path: "/mini/user/following/mark_read",  
253 - Handler: user.MiniUserFollowingMarkReadHandler(serverCtx),  
254 - },  
255 - {  
256 - Method: http.MethodPost,  
257 - Path: "/mini/user/follow",  
258 - Handler: user.MiniUserFollowHandler(serverCtx),  
259 - },  
260 - {  
261 - Method: http.MethodPost,  
262 - Path: "/mini/user/unfollow",  
263 - Handler: user.MiniUserUnFollowHandler(serverCtx),  
264 - },  
265 - {  
266 - Method: http.MethodPost,  
267 - Path: "/mini/user/mylike",  
268 - Handler: user.MiniMyLikeHandler(serverCtx),  
269 - },  
270 - }, 200 + rest.WithMiddlewares(
  201 + []rest.Middleware{serverCtx.LogRequest},
  202 + []rest.Route{
  203 + {
  204 + Method: http.MethodPost,
  205 + Path: "/mini/user/switch_account",
  206 + Handler: user.MiniUserSwitchAccountHandler(serverCtx),
  207 + },
  208 + {
  209 + Method: http.MethodPost,
  210 + Path: "/mini/user/info",
  211 + Handler: user.MiniUserInfoHandler(serverCtx),
  212 + },
  213 + {
  214 + Method: http.MethodPost,
  215 + Path: "/mini/user/statistics",
  216 + Handler: user.MiniUserStatisticsHandler(serverCtx),
  217 + },
  218 + {
  219 + Method: http.MethodPost,
  220 + Path: "/mini/user/audit_list",
  221 + Handler: user.MiniUserAuditListHandler(serverCtx),
  222 + },
  223 + {
  224 + Method: http.MethodPost,
  225 + Path: "/mini/user/audit",
  226 + Handler: user.MiniUserAuditHandler(serverCtx),
  227 + },
  228 + {
  229 + Method: http.MethodPost,
  230 + Path: "/mini/user/department_users",
  231 + Handler: user.MiniUserDepartmentUsersHandler(serverCtx),
  232 + },
  233 + {
  234 + Method: http.MethodPost,
  235 + Path: "/mini/user/user_list",
  236 + Handler: user.MiniUsersListHandler(serverCtx),
  237 + },
  238 + {
  239 + Method: http.MethodPost,
  240 + Path: "/mini/user/news",
  241 + Handler: user.MiniUserNewsHandler(serverCtx),
  242 + },
  243 + {
  244 + Method: http.MethodPost,
  245 + Path: "/mini/user/follower",
  246 + Handler: user.MiniUserFollowerHandler(serverCtx),
  247 + },
  248 + {
  249 + Method: http.MethodPost,
  250 + Path: "/mini/user/following",
  251 + Handler: user.MiniUserFollowingHandler(serverCtx),
  252 + },
  253 + {
  254 + Method: http.MethodPost,
  255 + Path: "/mini/user/following/latest_unread_list",
  256 + Handler: user.MiniUserFollowingLatestUnreadListHandler(serverCtx),
  257 + },
  258 + {
  259 + Method: http.MethodPost,
  260 + Path: "/mini/user/following/mark_read",
  261 + Handler: user.MiniUserFollowingMarkReadHandler(serverCtx),
  262 + },
  263 + {
  264 + Method: http.MethodPost,
  265 + Path: "/mini/user/follow",
  266 + Handler: user.MiniUserFollowHandler(serverCtx),
  267 + },
  268 + {
  269 + Method: http.MethodPost,
  270 + Path: "/mini/user/unfollow",
  271 + Handler: user.MiniUserUnFollowHandler(serverCtx),
  272 + },
  273 + {
  274 + Method: http.MethodPost,
  275 + Path: "/mini/user/mylike",
  276 + Handler: user.MiniMyLikeHandler(serverCtx),
  277 + },
  278 + }...,
  279 + ),
271 rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret), 280 rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
272 rest.WithPrefix("/v1"), 281 rest.WithPrefix("/v1"),
273 ) 282 )
274 283
275 server.AddRoutes( 284 server.AddRoutes(
276 rest.WithMiddlewares( 285 rest.WithMiddlewares(
277 - []rest.Middleware{serverCtx.LoginStatusCheck}, 286 + []rest.Middleware{serverCtx.LoginStatusCheck, serverCtx.LogRequest},
278 []rest.Route{ 287 []rest.Route{
279 { 288 {
280 Method: http.MethodPost, 289 Method: http.MethodPost,
@@ -338,31 +347,37 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { @@ -338,31 +347,37 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
338 ) 347 )
339 348
340 server.AddRoutes( 349 server.AddRoutes(
341 - []rest.Route{  
342 - {  
343 - Method: http.MethodPost,  
344 - Path: "/mini/company/search",  
345 - Handler: company.MiniCompanySearchHandler(serverCtx),  
346 - },  
347 - }, 350 + rest.WithMiddlewares(
  351 + []rest.Middleware{serverCtx.LogRequest},
  352 + []rest.Route{
  353 + {
  354 + Method: http.MethodPost,
  355 + Path: "/mini/company/search",
  356 + Handler: company.MiniCompanySearchHandler(serverCtx),
  357 + },
  358 + }...,
  359 + ),
348 rest.WithPrefix("/v1"), 360 rest.WithPrefix("/v1"),
349 ) 361 )
350 362
351 server.AddRoutes( 363 server.AddRoutes(
352 - []rest.Route{  
353 - {  
354 - Method: http.MethodPost,  
355 - Path: "/mini/company/search-joined",  
356 - Handler: company.MiniCompanySearchJoinedHandler(serverCtx),  
357 - },  
358 - }, 364 + rest.WithMiddlewares(
  365 + []rest.Middleware{serverCtx.LogRequest},
  366 + []rest.Route{
  367 + {
  368 + Method: http.MethodPost,
  369 + Path: "/mini/company/search-joined",
  370 + Handler: company.MiniCompanySearchJoinedHandler(serverCtx),
  371 + },
  372 + }...,
  373 + ),
359 rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret), 374 rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
360 rest.WithPrefix("/v1"), 375 rest.WithPrefix("/v1"),
361 ) 376 )
362 377
363 server.AddRoutes( 378 server.AddRoutes(
364 rest.WithMiddlewares( 379 rest.WithMiddlewares(
365 - []rest.Middleware{serverCtx.LoginStatusCheck}, 380 + []rest.Middleware{serverCtx.LoginStatusCheck, serverCtx.LogRequest},
366 []rest.Route{ 381 []rest.Route{
367 { 382 {
368 Method: http.MethodPost, 383 Method: http.MethodPost,
@@ -381,100 +396,103 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { @@ -381,100 +396,103 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
381 ) 396 )
382 397
383 server.AddRoutes( 398 server.AddRoutes(
384 - []rest.Route{  
385 - {  
386 - Method: http.MethodPost,  
387 - Path: "/article",  
388 - Handler: article.MiniCreateArticleHandler(serverCtx),  
389 - },  
390 - {  
391 - Method: http.MethodGet,  
392 - Path: "/article/:id",  
393 - Handler: article.MiniGetArticleHandler(serverCtx),  
394 - },  
395 - {  
396 - Method: http.MethodPost,  
397 - Path: "/article/user_like/list",  
398 - Handler: article.MiniUserLikeArticleHandler(serverCtx),  
399 - },  
400 - {  
401 - Method: http.MethodPost,  
402 - Path: "/article/user_like/set",  
403 - Handler: article.MiniSetUserLikeHandler(serverCtx),  
404 - },  
405 - {  
406 - Method: http.MethodPost,  
407 - Path: "/article/mark/user_read",  
408 - Handler: article.MiniArticleMarkUserReadHandler(serverCtx),  
409 - },  
410 - {  
411 - Method: http.MethodPost,  
412 - Path: "/article/mark/list",  
413 - Handler: article.MiniArticleMarkListHandler(serverCtx),  
414 - },  
415 - {  
416 - Method: http.MethodPost,  
417 - Path: "/article/search/me",  
418 - Handler: article.MiniArticleSearchMeHandler(serverCtx),  
419 - },  
420 - {  
421 - Method: http.MethodPost,  
422 - Path: "/article_draft",  
423 - Handler: article.MiniCreateArticleDraftHandler(serverCtx),  
424 - },  
425 - {  
426 - Method: http.MethodPut,  
427 - Path: "/article_draft",  
428 - Handler: article.MiniUpdateArticleDraftHandler(serverCtx),  
429 - },  
430 - {  
431 - Method: http.MethodPost,  
432 - Path: "/article_draft/search/me",  
433 - Handler: article.MiniSearchArticleDraftMeHandler(serverCtx),  
434 - },  
435 - {  
436 - Method: http.MethodGet,  
437 - Path: "/article_draft/me/:id",  
438 - Handler: article.MiniGetArticleDraftMeHandler(serverCtx),  
439 - },  
440 - {  
441 - Method: http.MethodDelete,  
442 - Path: "/article_draft/me/:id",  
443 - Handler: article.MiniDeleteArticleDraftMeHandler(serverCtx),  
444 - },  
445 - {  
446 - Method: http.MethodPost,  
447 - Path: "/article_backup/search",  
448 - Handler: article.MiniArticleBackupSearchHandler(serverCtx),  
449 - },  
450 - {  
451 - Method: http.MethodPost,  
452 - Path: "/article/set_tag",  
453 - Handler: article.MiniArticleSetTagHandler(serverCtx),  
454 - },  
455 - {  
456 - Method: http.MethodGet,  
457 - Path: "/article_tag/list/all",  
458 - Handler: article.MiniAllArticleTagHandler(serverCtx),  
459 - },  
460 - {  
461 - Method: http.MethodGet,  
462 - Path: "/show/home_page",  
463 - Handler: article.MiniShowHomePageHandler(serverCtx),  
464 - },  
465 - {  
466 - Method: http.MethodPost,  
467 - Path: "/show/search_article",  
468 - Handler: article.MiniSearchArticlePageHandler(serverCtx),  
469 - },  
470 - }, 399 + rest.WithMiddlewares(
  400 + []rest.Middleware{serverCtx.LogRequest},
  401 + []rest.Route{
  402 + {
  403 + Method: http.MethodPost,
  404 + Path: "/article",
  405 + Handler: article.MiniCreateArticleHandler(serverCtx),
  406 + },
  407 + {
  408 + Method: http.MethodGet,
  409 + Path: "/article/:id",
  410 + Handler: article.MiniGetArticleHandler(serverCtx),
  411 + },
  412 + {
  413 + Method: http.MethodPost,
  414 + Path: "/article/user_like/list",
  415 + Handler: article.MiniUserLikeArticleHandler(serverCtx),
  416 + },
  417 + {
  418 + Method: http.MethodPost,
  419 + Path: "/article/user_like/set",
  420 + Handler: article.MiniSetUserLikeHandler(serverCtx),
  421 + },
  422 + {
  423 + Method: http.MethodPost,
  424 + Path: "/article/mark/user_read",
  425 + Handler: article.MiniArticleMarkUserReadHandler(serverCtx),
  426 + },
  427 + {
  428 + Method: http.MethodPost,
  429 + Path: "/article/mark/list",
  430 + Handler: article.MiniArticleMarkListHandler(serverCtx),
  431 + },
  432 + {
  433 + Method: http.MethodPost,
  434 + Path: "/article/search/me",
  435 + Handler: article.MiniArticleSearchMeHandler(serverCtx),
  436 + },
  437 + {
  438 + Method: http.MethodPost,
  439 + Path: "/article_draft",
  440 + Handler: article.MiniCreateArticleDraftHandler(serverCtx),
  441 + },
  442 + {
  443 + Method: http.MethodPut,
  444 + Path: "/article_draft",
  445 + Handler: article.MiniUpdateArticleDraftHandler(serverCtx),
  446 + },
  447 + {
  448 + Method: http.MethodPost,
  449 + Path: "/article_draft/search/me",
  450 + Handler: article.MiniSearchArticleDraftMeHandler(serverCtx),
  451 + },
  452 + {
  453 + Method: http.MethodGet,
  454 + Path: "/article_draft/me/:id",
  455 + Handler: article.MiniGetArticleDraftMeHandler(serverCtx),
  456 + },
  457 + {
  458 + Method: http.MethodDelete,
  459 + Path: "/article_draft/me/:id",
  460 + Handler: article.MiniDeleteArticleDraftMeHandler(serverCtx),
  461 + },
  462 + {
  463 + Method: http.MethodPost,
  464 + Path: "/article_backup/search",
  465 + Handler: article.MiniArticleBackupSearchHandler(serverCtx),
  466 + },
  467 + {
  468 + Method: http.MethodPost,
  469 + Path: "/article/set_tag",
  470 + Handler: article.MiniArticleSetTagHandler(serverCtx),
  471 + },
  472 + {
  473 + Method: http.MethodGet,
  474 + Path: "/article_tag/list/all",
  475 + Handler: article.MiniAllArticleTagHandler(serverCtx),
  476 + },
  477 + {
  478 + Method: http.MethodGet,
  479 + Path: "/show/home_page",
  480 + Handler: article.MiniShowHomePageHandler(serverCtx),
  481 + },
  482 + {
  483 + Method: http.MethodPost,
  484 + Path: "/show/search_article",
  485 + Handler: article.MiniSearchArticlePageHandler(serverCtx),
  486 + },
  487 + }...,
  488 + ),
471 rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret), 489 rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
472 rest.WithPrefix("/v1/mini"), 490 rest.WithPrefix("/v1/mini"),
473 ) 491 )
474 492
475 server.AddRoutes( 493 server.AddRoutes(
476 rest.WithMiddlewares( 494 rest.WithMiddlewares(
477 - []rest.Middleware{serverCtx.LoginStatusCheck}, 495 + []rest.Middleware{serverCtx.LoginStatusCheck, serverCtx.LogRequest},
478 []rest.Route{ 496 []rest.Route{
479 { 497 {
480 Method: http.MethodGet, 498 Method: http.MethodGet,
@@ -519,7 +537,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { @@ -519,7 +537,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
519 537
520 server.AddRoutes( 538 server.AddRoutes(
521 rest.WithMiddlewares( 539 rest.WithMiddlewares(
522 - []rest.Middleware{serverCtx.LoginStatusCheck}, 540 + []rest.Middleware{serverCtx.LoginStatusCheck, serverCtx.LogRequest},
523 []rest.Route{ 541 []rest.Route{
524 { 542 {
525 Method: http.MethodGet, 543 Method: http.MethodGet,
@@ -554,7 +572,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { @@ -554,7 +572,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
554 572
555 server.AddRoutes( 573 server.AddRoutes(
556 rest.WithMiddlewares( 574 rest.WithMiddlewares(
557 - []rest.Middleware{serverCtx.LoginStatusCheck}, 575 + []rest.Middleware{serverCtx.LoginStatusCheck, serverCtx.LogRequest},
558 []rest.Route{ 576 []rest.Route{
559 { 577 {
560 Method: http.MethodPost, 578 Method: http.MethodPost,
  1 +package middleware
  2 +
  3 +import (
  4 + "github.com/zeromicro/go-zero/rest/handler"
  5 + "net/http"
  6 +)
  7 +
  8 +type LogRequestMiddleware struct {
  9 + logRequest bool
  10 +}
  11 +
  12 +// NewLogRequestMiddleware 记录请求
  13 +// logRequest true开启记录,false关闭记录
  14 +func NewLogRequestMiddleware(logRequest bool) *LogRequestMiddleware {
  15 + return &LogRequestMiddleware{
  16 + logRequest: logRequest,
  17 + }
  18 +}
  19 +
  20 +func (m *LogRequestMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
  21 + if !m.logRequest {
  22 + return func(writer http.ResponseWriter, request *http.Request) {
  23 + next(writer, request)
  24 + }
  25 + }
  26 + return handler.DetailedLogHandler(next).(http.HandlerFunc)
  27 +}
@@ -45,6 +45,7 @@ type ServiceContext struct { @@ -45,6 +45,7 @@ type ServiceContext struct {
45 SmsService smslib.SMSService 45 SmsService smslib.SMSService
46 46
47 LoginStatusCheck rest.Middleware 47 LoginStatusCheck rest.Middleware
  48 + LogRequest rest.Middleware
48 } 49 }
49 50
50 func NewServiceContext(c config.Config) *ServiceContext { 51 func NewServiceContext(c config.Config) *ServiceContext {
@@ -63,6 +64,7 @@ func NewServiceContext(c config.Config) *ServiceContext { @@ -63,6 +64,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
63 ApiAuthService: apiAuth, 64 ApiAuthService: apiAuth,
64 SmsService: smslib.SMSService{Service: gateway.NewService("短信服务", "https://sms.fjmaimaimai.com:9897", time.Second*5)}, 65 SmsService: smslib.SMSService{Service: gateway.NewService("短信服务", "https://sms.fjmaimaimai.com:9897", time.Second*5)},
65 LoginStatusCheck: middleware.NewLoginStatusCheckMiddleware(apiAuth).Handle, 66 LoginStatusCheck: middleware.NewLoginStatusCheckMiddleware(apiAuth).Handle,
  67 + LogRequest: middleware.NewLogRequestMiddleware(c.LogRequest).Handle,
66 68
67 ArticleBackupRepository: repository.NewArticleBackupRepository(cache.NewCachedRepository(mlCache)), 69 ArticleBackupRepository: repository.NewArticleBackupRepository(cache.NewCachedRepository(mlCache)),
68 ArticleCommentRepository: repository.NewArticleCommentRepository(cache.NewCachedRepository(mlCache)), 70 ArticleCommentRepository: repository.NewArticleCommentRepository(cache.NewCachedRepository(mlCache)),