remove spew

This commit is contained in:
aichy 2022-09-30 14:43:15 +08:00
parent d74e250d26
commit 6da181a7bf
3 changed files with 38 additions and 66 deletions

View File

@ -3,7 +3,6 @@ package middleware
import (
"strings"
"github.com/davecgh/go-spew/spew"
"github.com/segmentfault/answer/internal/schema"
"github.com/gin-gonic/gin"
@ -39,20 +38,13 @@ func (am *AuthUserMiddleware) Auth() gin.HandlerFunc {
ctx.Next()
return
}
if token == "888" {
userInfo := &entity.UserCacheInfo{}
userInfo.UserID = "2"
spew.Dump("开发环境 Auth", userInfo)
userInfo, err := am.authService.GetUserCacheInfo(ctx, token)
if err != nil {
ctx.Next()
return
}
if userInfo != nil {
ctx.Set(ctxUuidKey, userInfo)
} else {
userInfo, err := am.authService.GetUserCacheInfo(ctx, token)
if err != nil {
ctx.Next()
return
}
if userInfo != nil {
ctx.Set(ctxUuidKey, userInfo)
}
}
ctx.Next()
}
@ -67,38 +59,30 @@ func (am *AuthUserMiddleware) MustAuth() gin.HandlerFunc {
ctx.Abort()
return
}
if token == "888" {
userInfo := &entity.UserCacheInfo{}
userInfo.UserID = "2"
spew.Dump("开发环境 MustAuth", userInfo)
ctx.Set(ctxUuidKey, userInfo)
} else {
userInfo, err := am.authService.GetUserCacheInfo(ctx, token)
spew.Dump(userInfo, err)
if err != nil || userInfo == nil {
handler.HandleResponse(ctx, errors.Unauthorized(reason.UnauthorizedError), nil)
ctx.Abort()
return
}
if userInfo.EmailStatus != entity.EmailStatusAvailable {
handler.HandleResponse(ctx, errors.Forbidden(reason.EmailNeedToBeVerified),
&schema.ForbiddenResp{Type: schema.ForbiddenReasonTypeInactive})
ctx.Abort()
return
}
if userInfo.UserStatus == entity.UserStatusSuspended {
handler.HandleResponse(ctx, errors.Forbidden(reason.UserSuspended),
&schema.ForbiddenResp{Type: schema.ForbiddenReasonTypeUserSuspended})
ctx.Abort()
return
}
if userInfo.UserStatus == entity.UserStatusDeleted {
handler.HandleResponse(ctx, errors.Unauthorized(reason.UnauthorizedError), nil)
ctx.Abort()
return
}
ctx.Set(ctxUuidKey, userInfo)
userInfo, err := am.authService.GetUserCacheInfo(ctx, token)
if err != nil || userInfo == nil {
handler.HandleResponse(ctx, errors.Unauthorized(reason.UnauthorizedError), nil)
ctx.Abort()
return
}
if userInfo.EmailStatus != entity.EmailStatusAvailable {
handler.HandleResponse(ctx, errors.Forbidden(reason.EmailNeedToBeVerified),
&schema.ForbiddenResp{Type: schema.ForbiddenReasonTypeInactive})
ctx.Abort()
return
}
if userInfo.UserStatus == entity.UserStatusSuspended {
handler.HandleResponse(ctx, errors.Forbidden(reason.UserSuspended),
&schema.ForbiddenResp{Type: schema.ForbiddenReasonTypeUserSuspended})
ctx.Abort()
return
}
if userInfo.UserStatus == entity.UserStatusDeleted {
handler.HandleResponse(ctx, errors.Unauthorized(reason.UnauthorizedError), nil)
ctx.Abort()
return
}
ctx.Set(ctxUuidKey, userInfo)
ctx.Next()
}
}
@ -111,26 +95,19 @@ func (am *AuthUserMiddleware) CmsAuth() gin.HandlerFunc {
ctx.Abort()
return
}
if token == "888" {
userInfo := &entity.UserCacheInfo{}
userInfo.UserID = "2"
spew.Dump("开发环境 CmsAuth", userInfo)
ctx.Set(ctxUuidKey, userInfo)
} else {
userInfo, err := am.authService.GetCmsUserCacheInfo(ctx, token)
if err != nil {
userInfo, err := am.authService.GetCmsUserCacheInfo(ctx, token)
if err != nil {
handler.HandleResponse(ctx, errors.Unauthorized(reason.UnauthorizedError), nil)
ctx.Abort()
return
}
if userInfo != nil {
if userInfo.UserStatus == entity.UserStatusDeleted {
handler.HandleResponse(ctx, errors.Unauthorized(reason.UnauthorizedError), nil)
ctx.Abort()
return
}
if userInfo != nil {
if userInfo.UserStatus == entity.UserStatusDeleted {
handler.HandleResponse(ctx, errors.Unauthorized(reason.UnauthorizedError), nil)
ctx.Abort()
return
}
ctx.Set(ctxUuidKey, userInfo)
}
ctx.Set(ctxUuidKey, userInfo)
}
ctx.Next()
}

View File

@ -218,7 +218,6 @@ func (qr *questionRepo) SearchList(ctx context.Context, search *schema.QuestionS
session = session.Limit(search.PageSize, offset)
session = session.Select("question.id,question.user_id,question.title,question.original_text,question.parsed_text,question.status,question.view_count,question.unique_view_count,question.vote_count,question.answer_count,question.collection_count,question.follow_count,question.accepted_answer_id,question.last_answer_id,question.created_at,question.updated_at,question.post_update_time,question.revision_id")
count, err = session.FindAndCount(&rows)
//spew.Dump("search", err, count, rows)
if err != nil {
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
return rows, count, err

View File

@ -3,7 +3,6 @@ package schema
import (
"encoding/json"
"github.com/davecgh/go-spew/spew"
"github.com/jinzhu/copier"
"github.com/segmentfault/answer/internal/base/validator"
"github.com/segmentfault/answer/internal/entity"
@ -133,7 +132,6 @@ func (r *GetOtherUserInfoByUsernameResp) GetFromUserEntity(userInfo *entity.User
if ok {
r.Status = statusShow
}
spew.Dump(userInfo)
if userInfo.MailStatus == entity.EmailStatusToBeVerified {
statusMsgShow, ok := UserStatusShowMsg[11]
if ok {
@ -146,8 +144,6 @@ func (r *GetOtherUserInfoByUsernameResp) GetFromUserEntity(userInfo *entity.User
}
}
spew.Dump(r)
}
const (