改名 types 为 models

This commit is contained in:
Twilight 2024-07-14 22:14:20 +08:00
parent 8a29fc1875
commit 8231060f30
5 changed files with 11 additions and 11 deletions

View File

@ -5,7 +5,7 @@ import (
"framework_v2/consts" "framework_v2/consts"
"framework_v2/internal/providers" "framework_v2/internal/providers"
"framework_v2/internal/providers/jwks" "framework_v2/internal/providers/jwks"
"framework_v2/types" "framework_v2/models"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/mitchellh/mapstructure" "github.com/mitchellh/mapstructure"
"go.uber.org/zap" "go.uber.org/zap"
@ -29,9 +29,9 @@ func NewAuthLogic() *AuthLogic {
return &AuthLogic{} return &AuthLogic{}
} }
func (a *AuthLogic) GinMiddlewareAuth(tokenType types.JWTTokenTypes, c *gin.Context) (*types.User, error) { func (a *AuthLogic) GinMiddlewareAuth(tokenType models.JWTTokenTypes, c *gin.Context) (*models.User, error) {
var sub = consts.AnonymousUser var sub = consts.AnonymousUser
var jwtIdToken = &types.User{} var jwtIdToken = &models.User{}
if config.DebugMode.Enable { if config.DebugMode.Enable {
jwtIdToken.Token.Sub = sub jwtIdToken.Token.Sub = sub
@ -85,7 +85,7 @@ func (a *AuthLogic) GinMiddlewareAuth(tokenType types.JWTTokenTypes, c *gin.Cont
return jwtIdToken, nil return jwtIdToken, nil
} }
func (a *AuthLogic) GinUser(c *gin.Context) *types.User { func (a *AuthLogic) GinUser(c *gin.Context) *models.User {
user, _ := c.Get(consts.AuthMiddlewareKey) user, _ := c.Get(consts.AuthMiddlewareKey)
return user.(*types.User) return user.(*models.User)
} }

View File

@ -3,7 +3,7 @@ package grpc
import ( import (
"context" "context"
"framework_v2/internal/providers/jwks" "framework_v2/internal/providers/jwks"
"framework_v2/types" "framework_v2/models"
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/auth" "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/auth"
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/logging" "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/logging"
"github.com/mitchellh/mapstructure" "github.com/mitchellh/mapstructure"
@ -18,7 +18,7 @@ func JwtAuth(ctx context.Context) (context.Context, error) {
} }
sub := "anonymous" sub := "anonymous"
var jwtIdToken *types.User var jwtIdToken *models.User
if config.DebugMode.Enable { if config.DebugMode.Enable {
jwtIdToken.Token.Sub = sub jwtIdToken.Token.Sub = sub

View File

@ -4,14 +4,14 @@ import (
"framework_v2/consts" "framework_v2/consts"
"framework_v2/internal/logic" "framework_v2/internal/logic"
"framework_v2/internal/providers/helper" "framework_v2/internal/providers/helper"
"framework_v2/types" "framework_v2/models"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"net/http" "net/http"
) )
func RequireJWTIDToken(c *gin.Context) { func RequireJWTIDToken(c *gin.Context) {
auth := logic.NewAuthLogic() auth := logic.NewAuthLogic()
user, err := auth.GinMiddlewareAuth(types.JWTIDToken, c) user, err := auth.GinMiddlewareAuth(models.JWTIDToken, c)
if err != nil { if err != nil {
c.Abort() c.Abort()

View File

@ -81,7 +81,7 @@ func init() {
// switch argType { // switch argType {
// case reflect.TypeOf((*gin.Context)(nil)): // case reflect.TypeOf((*gin.Context)(nil)):
// argValue = reflect.ValueOf(c) // argValue = reflect.ValueOf(c)
// case reflect.TypeOf((*types.User)(nil)): // case reflect.TypeOf((*models.User)(nil)):
// userInfo := http2.DIJWTAuth(c) // userInfo := http2.DIJWTAuth(c)
// if userInfo == nil { // if userInfo == nil {
// helper.ResponseError(c, http.StatusUnauthorized, http2.ErrNotValidToken) // helper.ResponseError(c, http.StatusUnauthorized, http2.ErrNotValidToken)

View File

@ -1,4 +1,4 @@
package types package models
type UserTokenInfo struct { type UserTokenInfo struct {
Exp int `json:"exp"` Exp int `json:"exp"`