init.go 1.0 KB

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