Compare commits
No commits in common. "main" and "v0.0.49" have entirely different histories.
|
@ -22,11 +22,6 @@ var (
|
||||||
ErrJsonUnmarshal = NewError(114, "Json Unmarshal Fail")
|
ErrJsonUnmarshal = NewError(114, "Json Unmarshal Fail")
|
||||||
ErrJsonMarshal = NewError(115, "Json Marshal Fail")
|
ErrJsonMarshal = NewError(115, "Json Marshal Fail")
|
||||||
ErrInternal = NewError(116, "Internal Server Error")
|
ErrInternal = NewError(116, "Internal Server Error")
|
||||||
ErrPassword = NewError(117, "Password Incorrect")
|
|
||||||
ErrAccountNotFound = NewError(118, "Account Not Found")
|
|
||||||
ErrAccountDisabled = NewError(119, "Account Disabled")
|
|
||||||
ErrDisabled = NewError(120, "Status Disabled")
|
|
||||||
ErrRecordNotFound = NewError(121, "Record Not Found")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// jwt error code ,start:130
|
// jwt error code ,start:130
|
||||||
|
|
|
@ -8,29 +8,29 @@ import (
|
||||||
var Response Reply
|
var Response Reply
|
||||||
|
|
||||||
type Reply struct {
|
type Reply struct {
|
||||||
Code int32 `json:"code"`
|
Code int `json:"code"`
|
||||||
Message string `json:"message"`
|
Msg string `json:"msg"`
|
||||||
Result any `json:"result"`
|
Data any `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (reply *Reply) Success(ctx *gin.Context, data any) {
|
func (reply *Reply) Success(ctx *gin.Context, data any) {
|
||||||
reply.Code = 0
|
reply.Code = 200
|
||||||
reply.Result = data
|
reply.Data = data
|
||||||
reply.Message = ""
|
reply.Msg = ""
|
||||||
if data == nil {
|
if data == nil {
|
||||||
reply.Result = ""
|
reply.Data = ""
|
||||||
}
|
}
|
||||||
ctx.JSON(200, reply)
|
ctx.JSON(200, reply)
|
||||||
}
|
}
|
||||||
func (reply *Reply) Error(ctx *gin.Context, err error) {
|
func (reply *Reply) Error(ctx *gin.Context, err error) {
|
||||||
reply.Code = 500
|
reply.Code = 500
|
||||||
reply.Result = ""
|
reply.Data = ""
|
||||||
// Status code defaults to 500
|
// Status code defaults to 500
|
||||||
e, ok := status.FromError(err)
|
e, ok := status.FromError(err)
|
||||||
if ok {
|
if ok {
|
||||||
reply.Code = int32(e.Code())
|
reply.Code = int(e.Code())
|
||||||
}
|
}
|
||||||
reply.Message = e.Message()
|
reply.Msg = e.Message()
|
||||||
|
|
||||||
// Send error
|
// Send error
|
||||||
ctx.JSON(200, reply)
|
ctx.JSON(200, reply)
|
||||||
|
|
|
@ -2,6 +2,7 @@ package middleware
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
@ -32,14 +33,14 @@ func JwtAuth(redis *redis.RedisClient) gin.HandlerFunc {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 从redis 获取token,判断当前redis 是否为空
|
// 从redis 获取token,判断当前redis 是否为空
|
||||||
// tokenKey := fmt.Sprintf("%d-%s-%s", claims.ID, claims.Role, "token")
|
tokenKey := fmt.Sprintf("%d-%s-%s", claims.ID, claims.Role, "token")
|
||||||
// redisToken := redis.Client.Get(redis.Ctx, tokenKey)
|
redisToken := redis.Client.Get(redis.Ctx, tokenKey)
|
||||||
// if redisToken.Val() == "" {
|
if redisToken.Val() == "" {
|
||||||
// log.Println("redis异常", "Token status unauthorized")
|
log.Println("redis异常", "Token status unauthorized")
|
||||||
// c.JSON(http.StatusUnauthorized, gin.H{"error": "Token status unauthorized"})
|
c.JSON(http.StatusUnauthorized, gin.H{"error": "Token status unauthorized"})
|
||||||
// c.Abort()
|
c.Abort()
|
||||||
// return
|
return
|
||||||
// }
|
}
|
||||||
|
|
||||||
// 将解析后的 Token 存储到上下文中
|
// 将解析后的 Token 存储到上下文中
|
||||||
c.Set("Auth", claims)
|
c.Set("Auth", claims)
|
||||||
|
|
Loading…
Reference in New Issue