完成AllModels序列化

This commit is contained in:
eson
2023-06-21 12:21:56 +08:00
parent 389f12b8c5
commit 7fe53f749e
9 changed files with 260 additions and 34 deletions

View File

@@ -1,24 +1,27 @@
package svc
import (
"errors"
"fmt"
"fusenapi/initalize"
"fusenapi/model/gmodel"
"fusenapi/server/home-user-auth/internal/config"
"net/http"
"github.com/golang-jwt/jwt"
"gorm.io/gorm"
"errors"
"fmt"
"fusenapi/server/home-user-auth/internal/config"
"net/http"
)
type ServiceContext struct {
Config config.Config
Config config.Config
MysqlConn *gorm.DB
AllModels *gmodel.AllModelsGen
}
func NewServiceContext(c config.Config) *ServiceContext {
return &ServiceContext{
Config: c,
MysqlConn: initalize.InitMysql(c.SourceMysql),
@@ -28,8 +31,8 @@ func NewServiceContext(c config.Config) *ServiceContext {
func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, error) {
AuthKey := r.Header.Get("Authorization")
if AuthKey == "" {
return nil, nil
if len(AuthKey) <= 50 {
return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey)))
}
token, err := jwt.Parse(AuthKey, func(token *jwt.Token) (interface{}, error) {
@@ -38,7 +41,7 @@ func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err
return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
}
// 返回用于验证签名的密钥
return []byte(svcCtx.Config.Auth.AccessSecret), nil
return svcCtx.Config.Auth.AccessSecret, nil
})
if err != nil {
return nil, errors.New(fmt.Sprint("Error parsing token:", err))