init.go 992 B

1234567891011121314151617181920212223242526272829303132333435
  1. package middleware
  2. import (
  3. "git.cestong.com.cn/cecf/config-center-server/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. // 数据库链接
  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. }