作者 tangxvhui
... ... @@ -12,6 +12,7 @@ info(
@server(
prefix: v1/mini
group: article
middleware: LogRequest
jwt: MiniAuth
)
service Core {
... ... @@ -86,7 +87,7 @@ service Core {
@server(
prefix: v1/system
group: article
middleware: LoginStatusCheck
middleware: LoginStatusCheck,LogRequest
jwt: SystemAuth
)
service Core {
... ...
... ... @@ -11,7 +11,7 @@ info(
@server(
prefix: v1/system
group: tags
middleware: LoginStatusCheck
middleware: LoginStatusCheck,LogRequest
jwt: SystemAuth
)
service Core {
... ...
... ... @@ -12,6 +12,7 @@ info(
@server(
prefix: v1/mini
group: comment
middleware: LogRequest
jwt: MiniAuth
)
service Core {
... ... @@ -44,7 +45,7 @@ service Core {
@server(
prefix: v1/system
group: comment
middleware: LoginStatusCheck
middleware: LoginStatusCheck,LogRequest
jwt: SystemAuth
)
service Core {
... ...
... ... @@ -12,6 +12,7 @@ info(
@server(
prefix: v1
group: company
middleware: LogRequest
)
service Core {
@doc "公司搜索(公开的)"
... ... @@ -23,6 +24,7 @@ service Core {
@server(
prefix: v1
group: company
middleware: LogRequest
jwt : MiniAuth
)
service Core {
... ... @@ -31,11 +33,11 @@ service Core {
post /mini/company/search-joined(CompanySearchRequest) returns (CompanySearchResponse)
}
// 小程序接口
// 后台接口
@server(
prefix: v1
group: company
middleware: LoginStatusCheck
middleware: LoginStatusCheck,LogRequest
jwt : SystemAuth
)
service Core {
... ...
... ... @@ -11,7 +11,7 @@ info(
@server(
prefix: v1
group: department
middleware: LoginStatusCheck
middleware: LoginStatusCheck,LogRequest
jwt: SystemAuth
)
service Core {
... ...
... ... @@ -11,6 +11,7 @@ info(
@server(
prefix: v1
group: message
middleware: LogRequest
jwt: MiniAuth
)
service Core {
... ...
... ... @@ -11,7 +11,7 @@ info(
@server(
prefix: v1
group: role
middleware: LoginStatusCheck
middleware: LoginStatusCheck,LogRequest
jwt: SystemAuth
)
service Core {
... ...
... ... @@ -24,6 +24,7 @@ service Core {
@server(
prefix: v1
group: user
middleware: LogRequest
jwt: MiniAuth
)
service Core {
... ... @@ -255,7 +256,7 @@ type (
@server(
prefix: v1
group: user
middleware: LoginStatusCheck
middleware: LoginStatusCheck,LogRequest
jwt: SystemAuth
)
service Core {
... ...
... ... @@ -6,6 +6,8 @@ Migrate: false
Timeout: 30000
# CertFile: ./key/fjmaimaimai.com_bundle.crt
# KeyFile: ./key/fjmaimaimai.com.key
LogRequest: true # 记录详细请求日志
Log:
#Mode: file
Encoding: plain
... ...
... ... @@ -16,6 +16,7 @@ type Config struct {
Migrate bool `json:",optional,default=true"`
ApiAuth ApiService
DebugSmsCode string `json:",optional,default=999512"`
LogRequest bool `json:",optional,default=true"`
}
type ApiService struct {
... ...
... ... @@ -36,45 +36,48 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
)
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodPost,
Path: "/article_comment",
Handler: comment.MiniCreateArticleCommentHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article_comment/list",
Handler: comment.MiniListArticleCommentHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article_comment/top5",
Handler: comment.MiniTop5ArticleCommentHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/article_comment/:id",
Handler: comment.MiniGetArticleCommentHandler(serverCtx),
},
{
Method: http.MethodDelete,
Path: "/article_comment/:id",
Handler: comment.MiniDeleteArticleCommentHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article_comment/at_who/list",
Handler: comment.MiniArticleCommentAtWhoHandler(serverCtx),
},
},
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.LogRequest},
[]rest.Route{
{
Method: http.MethodPost,
Path: "/article_comment",
Handler: comment.MiniCreateArticleCommentHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article_comment/list",
Handler: comment.MiniListArticleCommentHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article_comment/top5",
Handler: comment.MiniTop5ArticleCommentHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/article_comment/:id",
Handler: comment.MiniGetArticleCommentHandler(serverCtx),
},
{
Method: http.MethodDelete,
Path: "/article_comment/:id",
Handler: comment.MiniDeleteArticleCommentHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article_comment/at_who/list",
Handler: comment.MiniArticleCommentAtWhoHandler(serverCtx),
},
}...,
),
rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
rest.WithPrefix("/v1/mini"),
)
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.LoginStatusCheck},
[]rest.Middleware{serverCtx.LoginStatusCheck, serverCtx.LogRequest},
[]rest.Route{
{
Method: http.MethodPost,
... ... @@ -113,30 +116,33 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
)
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodPost,
Path: "/mini/message/system",
Handler: message.MiniSystemHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/message/comment",
Handler: message.MiniCommentHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/message/like",
Handler: message.MiniLikeHandler(serverCtx),
},
},
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.LogRequest},
[]rest.Route{
{
Method: http.MethodPost,
Path: "/mini/message/system",
Handler: message.MiniSystemHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/message/comment",
Handler: message.MiniCommentHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/message/like",
Handler: message.MiniLikeHandler(serverCtx),
},
}...,
),
rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
rest.WithPrefix("/v1"),
)
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.LoginStatusCheck},
[]rest.Middleware{serverCtx.LoginStatusCheck, serverCtx.LogRequest},
[]rest.Route{
{
Method: http.MethodPost,
... ... @@ -191,90 +197,93 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
)
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodPost,
Path: "/mini/user/switch_account",
Handler: user.MiniUserSwitchAccountHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/user/info",
Handler: user.MiniUserInfoHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/user/statistics",
Handler: user.MiniUserStatisticsHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/user/audit_list",
Handler: user.MiniUserAuditListHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/user/audit",
Handler: user.MiniUserAuditHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/user/department_users",
Handler: user.MiniUserDepartmentUsersHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/user/user_list",
Handler: user.MiniUsersListHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/user/news",
Handler: user.MiniUserNewsHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/user/follower",
Handler: user.MiniUserFollowerHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/user/following",
Handler: user.MiniUserFollowingHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/user/following/latest_unread_list",
Handler: user.MiniUserFollowingLatestUnreadListHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/user/following/mark_read",
Handler: user.MiniUserFollowingMarkReadHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/user/follow",
Handler: user.MiniUserFollowHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/user/unfollow",
Handler: user.MiniUserUnFollowHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/user/mylike",
Handler: user.MiniMyLikeHandler(serverCtx),
},
},
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.LogRequest},
[]rest.Route{
{
Method: http.MethodPost,
Path: "/mini/user/switch_account",
Handler: user.MiniUserSwitchAccountHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/user/info",
Handler: user.MiniUserInfoHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/user/statistics",
Handler: user.MiniUserStatisticsHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/user/audit_list",
Handler: user.MiniUserAuditListHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/user/audit",
Handler: user.MiniUserAuditHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/user/department_users",
Handler: user.MiniUserDepartmentUsersHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/user/user_list",
Handler: user.MiniUsersListHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/user/news",
Handler: user.MiniUserNewsHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/user/follower",
Handler: user.MiniUserFollowerHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/user/following",
Handler: user.MiniUserFollowingHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/user/following/latest_unread_list",
Handler: user.MiniUserFollowingLatestUnreadListHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/user/following/mark_read",
Handler: user.MiniUserFollowingMarkReadHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/user/follow",
Handler: user.MiniUserFollowHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/user/unfollow",
Handler: user.MiniUserUnFollowHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/user/mylike",
Handler: user.MiniMyLikeHandler(serverCtx),
},
}...,
),
rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
rest.WithPrefix("/v1"),
)
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.LoginStatusCheck},
[]rest.Middleware{serverCtx.LoginStatusCheck, serverCtx.LogRequest},
[]rest.Route{
{
Method: http.MethodPost,
... ... @@ -338,31 +347,37 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
)
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodPost,
Path: "/mini/company/search",
Handler: company.MiniCompanySearchHandler(serverCtx),
},
},
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.LogRequest},
[]rest.Route{
{
Method: http.MethodPost,
Path: "/mini/company/search",
Handler: company.MiniCompanySearchHandler(serverCtx),
},
}...,
),
rest.WithPrefix("/v1"),
)
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodPost,
Path: "/mini/company/search-joined",
Handler: company.MiniCompanySearchJoinedHandler(serverCtx),
},
},
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.LogRequest},
[]rest.Route{
{
Method: http.MethodPost,
Path: "/mini/company/search-joined",
Handler: company.MiniCompanySearchJoinedHandler(serverCtx),
},
}...,
),
rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
rest.WithPrefix("/v1"),
)
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.LoginStatusCheck},
[]rest.Middleware{serverCtx.LoginStatusCheck, serverCtx.LogRequest},
[]rest.Route{
{
Method: http.MethodPost,
... ... @@ -381,100 +396,103 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
)
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodPost,
Path: "/article",
Handler: article.MiniCreateArticleHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/article/:id",
Handler: article.MiniGetArticleHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article/user_like/list",
Handler: article.MiniUserLikeArticleHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article/user_like/set",
Handler: article.MiniSetUserLikeHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article/mark/user_read",
Handler: article.MiniArticleMarkUserReadHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article/mark/list",
Handler: article.MiniArticleMarkListHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article/search/me",
Handler: article.MiniArticleSearchMeHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article_draft",
Handler: article.MiniCreateArticleDraftHandler(serverCtx),
},
{
Method: http.MethodPut,
Path: "/article_draft",
Handler: article.MiniUpdateArticleDraftHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article_draft/search/me",
Handler: article.MiniSearchArticleDraftMeHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/article_draft/me/:id",
Handler: article.MiniGetArticleDraftMeHandler(serverCtx),
},
{
Method: http.MethodDelete,
Path: "/article_draft/me/:id",
Handler: article.MiniDeleteArticleDraftMeHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article_backup/search",
Handler: article.MiniArticleBackupSearchHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article/set_tag",
Handler: article.MiniArticleSetTagHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/article_tag/list/all",
Handler: article.MiniAllArticleTagHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/show/home_page",
Handler: article.MiniShowHomePageHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/show/search_article",
Handler: article.MiniSearchArticlePageHandler(serverCtx),
},
},
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.LogRequest},
[]rest.Route{
{
Method: http.MethodPost,
Path: "/article",
Handler: article.MiniCreateArticleHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/article/:id",
Handler: article.MiniGetArticleHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article/user_like/list",
Handler: article.MiniUserLikeArticleHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article/user_like/set",
Handler: article.MiniSetUserLikeHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article/mark/user_read",
Handler: article.MiniArticleMarkUserReadHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article/mark/list",
Handler: article.MiniArticleMarkListHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article/search/me",
Handler: article.MiniArticleSearchMeHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article_draft",
Handler: article.MiniCreateArticleDraftHandler(serverCtx),
},
{
Method: http.MethodPut,
Path: "/article_draft",
Handler: article.MiniUpdateArticleDraftHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article_draft/search/me",
Handler: article.MiniSearchArticleDraftMeHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/article_draft/me/:id",
Handler: article.MiniGetArticleDraftMeHandler(serverCtx),
},
{
Method: http.MethodDelete,
Path: "/article_draft/me/:id",
Handler: article.MiniDeleteArticleDraftMeHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article_backup/search",
Handler: article.MiniArticleBackupSearchHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article/set_tag",
Handler: article.MiniArticleSetTagHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/article_tag/list/all",
Handler: article.MiniAllArticleTagHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/show/home_page",
Handler: article.MiniShowHomePageHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/show/search_article",
Handler: article.MiniSearchArticlePageHandler(serverCtx),
},
}...,
),
rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
rest.WithPrefix("/v1/mini"),
)
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.LoginStatusCheck},
[]rest.Middleware{serverCtx.LoginStatusCheck, serverCtx.LogRequest},
[]rest.Route{
{
Method: http.MethodGet,
... ... @@ -519,7 +537,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.LoginStatusCheck},
[]rest.Middleware{serverCtx.LoginStatusCheck, serverCtx.LogRequest},
[]rest.Route{
{
Method: http.MethodGet,
... ... @@ -554,7 +572,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.LoginStatusCheck},
[]rest.Middleware{serverCtx.LoginStatusCheck, serverCtx.LogRequest},
[]rest.Route{
{
Method: http.MethodPost,
... ...
package middleware
import (
"github.com/zeromicro/go-zero/rest/handler"
"net/http"
)
type LogRequestMiddleware struct {
logRequest bool
}
// NewLogRequestMiddleware 记录请求
// logRequest true开启记录,false关闭记录
func NewLogRequestMiddleware(logRequest bool) *LogRequestMiddleware {
return &LogRequestMiddleware{
logRequest: logRequest,
}
}
func (m *LogRequestMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
if !m.logRequest {
return func(writer http.ResponseWriter, request *http.Request) {
next(writer, request)
}
}
return handler.DetailedLogHandler(next).(http.HandlerFunc)
}
... ...
... ... @@ -45,6 +45,7 @@ type ServiceContext struct {
SmsService smslib.SMSService
LoginStatusCheck rest.Middleware
LogRequest rest.Middleware
}
func NewServiceContext(c config.Config) *ServiceContext {
... ... @@ -63,6 +64,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
ApiAuthService: apiAuth,
SmsService: smslib.SMSService{Service: gateway.NewService("短信服务", "https://sms.fjmaimaimai.com:9897", time.Second*5)},
LoginStatusCheck: middleware.NewLoginStatusCheckMiddleware(apiAuth).Handle,
LogRequest: middleware.NewLogRequestMiddleware(c.LogRequest).Handle,
ArticleBackupRepository: repository.NewArticleBackupRepository(cache.NewCachedRepository(mlCache)),
ArticleCommentRepository: repository.NewArticleCommentRepository(cache.NewCachedRepository(mlCache)),
... ...