蛋蛋星球 后台端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

32 lines
577 B

  1. package mw
  2. import (
  3. "applet/app/e"
  4. "applet/app/svc"
  5. "errors"
  6. "github.com/gin-gonic/gin"
  7. )
  8. // Auth 检查权限, 签名等等
  9. func Auth(c *gin.Context) {
  10. admin, err := svc.CheckUser(c)
  11. if err != nil {
  12. var e1 e.E
  13. switch {
  14. case errors.As(err, &e1):
  15. e.OutErr(c, e1.Code, e1.Error())
  16. return
  17. default:
  18. e.OutErr(c, e.ERR_UNAUTHORIZED, err.Error())
  19. return
  20. }
  21. }
  22. if admin == nil {
  23. e.OutErr(c, e.ERR_NOT_AUTH, "当前管理员信息失效")
  24. return
  25. }
  26. // 将当前请求的username信息保存到请求的上下文c上
  27. c.Set("admin", admin)
  28. c.Next()
  29. }