u
This commit is contained in:
1 parent
994321d049
commit
b68a37f40b
7 files changed
+91
-47
No files matched your search
@@ -4,12 +4,17 @@ import (
|
||||
response "base-go-v2/internal/reponse"
|
||||
"base-go-v2/internal/router"
|
||||
"base-go-v2/internal/utils/jwtx"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func AuthMiddleware() router.HandlerFunc {
|
||||
return func(c *router.Context) error {
|
||||
fmt.Println("===请求进入===")
|
||||
|
||||
token := c.Header("token")
|
||||
if token == "" {
|
||||
fmt.Println("===未提供 Token===")
|
||||
|
||||
c.Abort()
|
||||
return response.Fail(c).
|
||||
Code(response.HttpCode.Unauthorized).
|
||||
@@ -22,11 +27,13 @@ func AuthMiddleware() router.HandlerFunc {
|
||||
// Access Token 有效
|
||||
if tokenVerify.IsValid {
|
||||
c.SetUserID(tokenVerify.Claims.UserID)
|
||||
return nil
|
||||
return c.Next()
|
||||
}
|
||||
|
||||
// Access Token 失效 → 返回刷新提示
|
||||
if !tokenVerify.IsValid {
|
||||
fmt.Println("===Access Token 失效===")
|
||||
|
||||
c.Abort()
|
||||
return response.Fail(c).
|
||||
Code(response.HttpCode.RefreshToken).
|
||||
@@ -34,6 +41,7 @@ func AuthMiddleware() router.HandlerFunc {
|
||||
Send()
|
||||
}
|
||||
|
||||
fmt.Println("===请求通过===")
|
||||
return c.Next()
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,9 @@ func InitDefaultCategories(userID int64) error {
|
||||
fmt.Printf("系统分类数量: %d\n", len(sysCategories))
|
||||
|
||||
// 2. 构建批量插入数据
|
||||
userCategories := make([]mapx.M, 0, len(sysCategories))
|
||||
//userCategories := make([]mapx.M, 0, len(sysCategories))
|
||||
userCategories := mapx.NewArr(len(sysCategories))
|
||||
|
||||
for i, row := range sysCategories {
|
||||
m := mapx.New().SetKV(
|
||||
"id", idgen.NextId(),
|
||||
@@ -52,6 +54,7 @@ func InitDefaultCategories(userID int64) error {
|
||||
}
|
||||
|
||||
func getUserCategory(c *router.Context) error {
|
||||
fmt.Println("请求进入了====")
|
||||
userId := c.GetUserID()
|
||||
|
||||
// 查询当前用户的分类
|
||||
|
||||
@@ -19,6 +19,6 @@ func InitAppRouter() *router.Router {
|
||||
|
||||
auth.InitAuthRouter(r)
|
||||
money.InitMoneyRouter(r)
|
||||
|
||||
|
||||
return r
|
||||
}
|
||||
@@ -13,8 +13,12 @@ func New() M {
|
||||
return M{}
|
||||
}
|
||||
|
||||
func NewArr() {
|
||||
//return make([]M, 0, len())
|
||||
func NewArr(cap ...int) []M {
|
||||
c := 0
|
||||
if len(cap) > 0 {
|
||||
c = cap[0]
|
||||
}
|
||||
return make([]M, 0, c)
|
||||
}
|
||||
|
||||
// Set 设置单个键值,支持链式调用
|
||||
|
||||
Reference in new issue
Block a user