|
- package mw
-
- import (
- "applet/app/e"
- "applet/app/svc"
- "errors"
- "github.com/gin-gonic/gin"
- )
-
- // Auth 检查权限, 签名等等
- func Auth(c *gin.Context) {
- admin, err := svc.CheckUser(c)
- if err != nil {
- var e1 e.E
- switch {
- case errors.As(err, &e1):
- e.OutErr(c, e1.Code, e1.Error())
- return
- default:
- e.OutErr(c, e.ERR_UNAUTHORIZED, err.Error())
- return
- }
- }
- if admin == nil {
- e.OutErr(c, e.ERR_NOT_AUTH, "当前管理员信息失效")
- return
- }
- // 将当前请求的username信息保存到请求的上下文c上
- c.Set("admin", admin)
- c.Next()
- }
|