感动中国

This commit is contained in:
eson
2023-08-10 12:04:36 +08:00
parent 68488da99c
commit 440f13bee8
102 changed files with 146 additions and 125 deletions

View File

@@ -10,6 +10,7 @@ import (
"github.com/golang-jwt/jwt"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest/httpx"
"gorm.io/gorm"
)
var DefaultJwtSecret uint64 = 21321321321
@@ -51,7 +52,7 @@ func NormalAfterLogic(w http.ResponseWriter, r *http.Request, resp *Response) {
}
}
func RequestParse(w http.ResponseWriter, r *http.Request, state *shared.SharedState, LogicRequest any) (*auth.UserInfo, error) {
func RequestParse(w http.ResponseWriter, r *http.Request, svcCtx any, LogicRequest any) (*auth.UserInfo, error) {
// log.Println(io.ReadAll(r.Body))
token, info, err := auth.ParseJwtTokenHeader[auth.UserInfo](r) //解析Token头, 和payload信息
if err != nil {
@@ -63,7 +64,13 @@ func RequestParse(w http.ResponseWriter, r *http.Request, state *shared.SharedSt
if info != nil {
if info.IsUser() {
us, err := state.GetUserState(info.UserId) //获取缓存的用户状态
// us, err := state.GetUserState(info.UserId) //获取缓存的用户状态
reflect.ValueOf(svcCtx)
ctxValue := reflect.ValueOf(svcCtx).FieldByName("MysqlConn")
gdb := ctxValue.Interface().(*gorm.DB)
us, err := shared.GetUserState(info.UserId, gdb)
if err != nil {
logx.Error(err)
return nil, err