init.go 945 B

123456789101112131415161718192021222324252627282930313233343536
  1. package middleware
  2. import (
  3. "cold-logistics/common/actions"
  4. "github.com/gin-gonic/gin"
  5. jwt "gogs.baozhida.cn/zoie/OAuth-core/pkg/jwtauth"
  6. "gogs.baozhida.cn/zoie/OAuth-core/sdk"
  7. )
  8. const (
  9. JwtTokenCheck string = "JwtToken"
  10. RoleCheck string = "AuthCheckRole"
  11. PermissionCheck string = "PermissionAction"
  12. )
  13. func InitMiddleware(r *gin.Engine) {
  14. // 数据库链接
  15. r.Use(WithContextDb)
  16. // 日志处理
  17. r.Use(LoggerToFile())
  18. // 自定义错误处理
  19. r.Use(CustomError)
  20. // NoCache is a middleware function that appends headers
  21. r.Use(NoCache)
  22. // 跨域处理
  23. r.Use(Options)
  24. // Secure is a middleware function that appends security
  25. r.Use(Secure)
  26. //r.Use(DemoEvn())
  27. // 链路追踪
  28. //r.Use(middleware.Trace())
  29. sdk.Runtime.SetMiddleware(JwtTokenCheck, (*jwt.GinJWTMiddleware).MiddlewareFunc)
  30. //sdk.Runtime.SetMiddleware(RoleCheck, AuthCheckRole())
  31. sdk.Runtime.SetMiddleware(PermissionCheck, actions.PermissionAction())
  32. }