package middlewares import ( "strings" "github.com/beego/beego/v2/server/web/context" "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant" "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" ) func CheckFontToken() func(ctx *context.Context) { return func(ctx *context.Context) { // adminToken := ctx.Input.Header("x-font-token") // Bearer authorization_token adminToken := ctx.Input.Header("Authorization") //以一个空格" ",做切分 strList := strings.Split(adminToken, " ") if len(strList) > 1 { adminToken = strList[1] } if len(strList) == 1 { adminToken = strList[0] } userAuth, err := (&domain.UserAuth{}).ParseAccessToken(adminToken) if err != nil || userAuth.UserId <= 0 { forbidden(ctx) return } if userAuth.PlatformId != constant.PLATFORM_FONT_ID { forbidden(ctx) return } ctx.Input.SetData(domain.UserAuth{}, userAuth) } }