package router import ( "demo/share" "github.com/gin-gonic/gin" "strconv" ) func CreateResult() gin.H { return gin.H{ "code": 200, "msg": "success", } } func CreateResultData(Data any) gin.H { return gin.H{ "code": 200, "msg": "success", "data": Data, } } func CreateResultError(errCode int, errMsg string) gin.H { return gin.H{ "code": errCode, "msg": errMsg, } } func GetUserIdByToken(c *gin.Context) int { header := c.GetHeader("auth-sign") if header == "" { c.JSON(200, CreateResultError(401, "用户未登录")) return 0 } claims, err := share.ParseToken(header) if err != nil { c.JSON(200, CreateResultError(401, "用户未登录")) return 0 } i, err := strconv.ParseInt(claims["iss"].(string), 10, 32) return int(i) }