casbin.go 834 B

123456789101112131415161718192021222324252627
  1. package global
  2. import (
  3. "github.com/casbin/casbin/v2"
  4. "github.com/gin-gonic/gin"
  5. "gogs.baozhida.cn/zoie/OAuth-core/api"
  6. "gogs.baozhida.cn/zoie/OAuth-core/sdk"
  7. "gogs.baozhida.cn/zoie/OAuth-core/sdk/config"
  8. )
  9. func LoadPolicy(c *gin.Context) (*casbin.SyncedEnforcer, error) {
  10. log := api.GetRequestLogger(c)
  11. //if err := sdk.Runtime.GetCasbinKey(c.Request.Host).LoadPolicy(); err == nil {
  12. // return sdk.Runtime.GetCasbinKey(c.Request.Host), nil
  13. //} else {
  14. // log.Errorf("casbin rbac_model or policy init error, %s ", err.Error())
  15. // return nil, err
  16. //}
  17. if err := sdk.Runtime.GetCasbinKey(config.ApplicationConfig.Host).LoadPolicy(); err == nil {
  18. return sdk.Runtime.GetCasbinKey(config.ApplicationConfig.Host), nil
  19. } else {
  20. log.Errorf("casbin rbac_model or policy init error, %s ", err.Error())
  21. return nil, err
  22. }
  23. }