面包店
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.

mw_auth.go 570 B

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