智慧食堂
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.

30 lines
560 B

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