🐛 fix session bug
This commit is contained in:
@@ -3,7 +3,9 @@ package captcha
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/captcha"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||
)
|
||||
@@ -13,7 +15,8 @@ func GenerateRotateCaptchaHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
l := captcha.NewGenerateRotateCaptchaLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GenerateRotateCaptcha()
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
|
@@ -3,7 +3,9 @@ package captcha
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/captcha"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||
)
|
||||
@@ -13,7 +15,8 @@ func GenerateSlideBasicCaptchaHandler(svcCtx *svc.ServiceContext) http.HandlerFu
|
||||
l := captcha.NewGenerateSlideBasicCaptchaLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GenerateSlideBasicCaptcha()
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ package client
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/common/utils"
|
||||
@@ -15,8 +16,9 @@ func GenerateClientIdHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
clientIP := utils.GetClientIP(r)
|
||||
l := client.NewGenerateClientIdLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GenerateClientId(clientIP)
|
||||
if err != nil || resp.Code == 500 {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
|
@@ -0,0 +1,31 @@
|
||||
package comment
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/comment"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/types"
|
||||
)
|
||||
|
||||
func DislikeCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.CommentDisLikeRequest
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := comment.NewDislikeCommentLogic(r.Context(), svcCtx)
|
||||
resp, err := l.DislikeComment(&req)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
package comment
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/comment"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/types"
|
||||
)
|
||||
|
||||
func GetCommentListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.CommentListRequest
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := comment.NewGetCommentListLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetCommentList(&req)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
package comment
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/comment"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/types"
|
||||
)
|
||||
|
||||
func GetReplyListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.ReplyListRequest
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := comment.NewGetReplyListLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetReplyList(&req)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
package comment
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/comment"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/types"
|
||||
)
|
||||
|
||||
func LikeCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.CommentLikeRequest
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := comment.NewLikeCommentLogic(r.Context(), svcCtx)
|
||||
resp, err := l.LikeComment(&req)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
package comment
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/comment"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/types"
|
||||
)
|
||||
|
||||
func SubmitCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.CommentRequest
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := comment.NewSubmitCommentLogic(r.Context(), svcCtx)
|
||||
resp, err := l.SubmitComment(&req)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
package comment
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/comment"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/types"
|
||||
)
|
||||
|
||||
func SubmitReplyCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.ReplyCommentRequest
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := comment.NewSubmitReplyCommentLogic(r.Context(), svcCtx)
|
||||
resp, err := l.SubmitReplyComment(&req)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
package comment
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/comment"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/types"
|
||||
)
|
||||
|
||||
func SubmitReplyReplyHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.ReplyReplyRequest
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := comment.NewSubmitReplyReplyLogic(r.Context(), svcCtx)
|
||||
resp, err := l.SubmitReplyReply(&req)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
@@ -3,7 +3,9 @@ package oauth
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/oauth"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||
)
|
||||
@@ -13,7 +15,8 @@ func GetGiteeOauthUrlHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
l := oauth.NewGetGiteeOauthUrlLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetGiteeOauthUrl()
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
|
@@ -3,7 +3,9 @@ package oauth
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/oauth"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/types"
|
||||
@@ -20,7 +22,8 @@ func GetGithubOauthUrlHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
l := oauth.NewGetGithubOauthUrlLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetGithubOauthUrl(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
|
@@ -3,7 +3,9 @@ package oauth
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/oauth"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/types"
|
||||
@@ -20,7 +22,8 @@ func GetQqOauthUrlHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
l := oauth.NewGetQqOauthUrlLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetQqOauthUrl(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ package oauth
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/oauth"
|
||||
@@ -21,7 +22,8 @@ func GetWechatQrcodeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
l := oauth.NewGetWechatQrcodeLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetWechatQrcode(r, &req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
|
@@ -1,8 +1,10 @@
|
||||
package oauth
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/oauth"
|
||||
@@ -21,7 +23,8 @@ func GiteeCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
l := oauth.NewGiteeCallbackLogic(r.Context(), svcCtx)
|
||||
err := l.GiteeCallback(w, r, &req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
logx.Error(err)
|
||||
httpx.ErrorCtx(r.Context(), w, errors.New("server error"))
|
||||
} else {
|
||||
httpx.Ok(w)
|
||||
}
|
||||
|
@@ -1,8 +1,10 @@
|
||||
package oauth
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/oauth"
|
||||
@@ -21,7 +23,8 @@ func GithubCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
l := oauth.NewGithubCallbackLogic(r.Context(), svcCtx)
|
||||
err := l.GithubCallback(w, r, &req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
logx.Error(err)
|
||||
httpx.ErrorCtx(r.Context(), w, errors.New("server error"))
|
||||
} else {
|
||||
httpx.Ok(w)
|
||||
}
|
||||
|
@@ -1,8 +1,10 @@
|
||||
package oauth
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/oauth"
|
||||
@@ -21,7 +23,8 @@ func QqCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
l := oauth.NewQqCallbackLogic(r.Context(), svcCtx)
|
||||
err := l.QqCallback(w, r, &req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
logx.Error(err)
|
||||
httpx.ErrorCtx(r.Context(), w, errors.New("server error"))
|
||||
} else {
|
||||
httpx.Ok(w)
|
||||
}
|
||||
|
@@ -1,8 +1,10 @@
|
||||
package oauth
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/oauth"
|
||||
@@ -14,7 +16,8 @@ func WechatCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
l := oauth.NewWechatCallbackLogic(r.Context(), svcCtx)
|
||||
err := l.WechatCallback(w, r)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
logx.Error(err)
|
||||
httpx.ErrorCtx(r.Context(), w, errors.New("server error"))
|
||||
} else {
|
||||
httpx.Ok(w)
|
||||
}
|
||||
|
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
captcha "schisandra-album-cloud-microservices/app/core/api/internal/handler/captcha"
|
||||
client "schisandra-album-cloud-microservices/app/core/api/internal/handler/client"
|
||||
comment "schisandra-album-cloud-microservices/app/core/api/internal/handler/comment"
|
||||
oauth "schisandra-album-cloud-microservices/app/core/api/internal/handler/oauth"
|
||||
sms "schisandra-album-cloud-microservices/app/core/api/internal/handler/sms"
|
||||
user "schisandra-album-cloud-microservices/app/core/api/internal/handler/user"
|
||||
@@ -56,6 +57,54 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
rest.WithMaxBytes(1048576),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
rest.WithMiddlewares(
|
||||
[]rest.Middleware{serverCtx.SecurityHeadersMiddleware, serverCtx.CasbinVerifyMiddleware},
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/dislike",
|
||||
Handler: comment.DislikeCommentHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/like",
|
||||
Handler: comment.LikeCommentHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/list",
|
||||
Handler: comment.GetCommentListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/reply/list",
|
||||
Handler: comment.GetReplyListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/reply/reply/submit",
|
||||
Handler: comment.SubmitReplyReplyHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/reply/submit",
|
||||
Handler: comment.SubmitReplyCommentHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/submit",
|
||||
Handler: comment.SubmitCommentHandler(serverCtx),
|
||||
},
|
||||
}...,
|
||||
),
|
||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||
rest.WithSignature(serverCtx.Config.Signature),
|
||||
rest.WithPrefix("/api/auth/comment"),
|
||||
rest.WithTimeout(10000*time.Millisecond),
|
||||
rest.WithMaxBytes(1048576),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
rest.WithMiddlewares(
|
||||
[]rest.Middleware{serverCtx.SecurityHeadersMiddleware},
|
||||
@@ -184,6 +233,5 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
},
|
||||
},
|
||||
rest.WithPrefix("/api/ws"),
|
||||
rest.WithTimeout(10000*time.Millisecond),
|
||||
)
|
||||
}
|
||||
|
@@ -3,7 +3,9 @@ package sms
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/sms"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/types"
|
||||
@@ -20,7 +22,8 @@ func SendSmsByAliyunHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
l := sms.NewSendSmsByAliyunLogic(r.Context(), svcCtx)
|
||||
resp, err := l.SendSmsByAliyun(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
|
@@ -3,7 +3,9 @@ package sms
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/sms"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/types"
|
||||
@@ -20,7 +22,8 @@ func SendSmsBySmsbaoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
l := sms.NewSendSmsBySmsbaoLogic(r.Context(), svcCtx)
|
||||
resp, err := l.SendSmsBySmsbao(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
|
@@ -3,7 +3,9 @@ package sms
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/sms"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/types"
|
||||
@@ -20,7 +22,8 @@ func SendSmsByTestHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
l := sms.NewSendSmsByTestLogic(r.Context(), svcCtx)
|
||||
resp, err := l.SendSmsByTest(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ package user
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/user"
|
||||
@@ -20,8 +21,9 @@ func AccountLoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
|
||||
l := user.NewAccountLoginLogic(r.Context(), svcCtx)
|
||||
resp, err := l.AccountLogin(w, r, &req)
|
||||
if err != nil || resp.Code == 500 {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
|
@@ -1,8 +1,10 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/user"
|
||||
@@ -14,7 +16,8 @@ func GetUserDeviceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
l := user.NewGetUserDeviceLogic(r.Context(), svcCtx)
|
||||
err := l.GetUserDevice(r)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
logx.Error(err)
|
||||
httpx.ErrorCtx(r.Context(), w, errors.New("server error"))
|
||||
} else {
|
||||
httpx.Ok(w)
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ package user
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/user"
|
||||
@@ -21,7 +22,8 @@ func PhoneLoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
l := user.NewPhoneLoginLogic(r.Context(), svcCtx)
|
||||
resp, err := l.PhoneLogin(r, w, &req)
|
||||
if err != nil || resp.Code == 500 {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ package user
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/user"
|
||||
@@ -14,7 +15,8 @@ func RefreshTokenHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
l := user.NewRefreshTokenLogic(r.Context(), svcCtx)
|
||||
resp, err := l.RefreshToken(r)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ package user
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/user"
|
||||
@@ -20,8 +21,9 @@ func ResetPasswordHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
|
||||
l := user.NewResetPasswordLogic(r.Context(), svcCtx)
|
||||
resp, err := l.ResetPassword(&req)
|
||||
if err != nil || resp.Code == 500 {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
httpx.WriteJsonCtx(r.Context(), w, http.StatusInternalServerError, resp)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
|
@@ -3,8 +3,6 @@ package websocket
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/websocket"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||
)
|
||||
@@ -12,11 +10,6 @@ import (
|
||||
func MessageWebsocketHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := websocket.NewMessageWebsocketLogic(r.Context(), svcCtx)
|
||||
err := l.MessageWebsocket(w, r)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.Ok(w)
|
||||
}
|
||||
l.MessageWebsocket(w, r)
|
||||
}
|
||||
}
|
||||
|
@@ -3,8 +3,6 @@ package websocket
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/logic/websocket"
|
||||
"schisandra-album-cloud-microservices/app/core/api/internal/svc"
|
||||
)
|
||||
@@ -12,11 +10,6 @@ import (
|
||||
func QrcodeWebsocketHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := websocket.NewQrcodeWebsocketLogic(r.Context(), svcCtx)
|
||||
err := l.QrcodeWebsocket(w, r)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.Ok(w)
|
||||
}
|
||||
l.QrcodeWebsocket(w, r)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user