casbin.go 521 B

123456789101112131415161718
  1. package global
  2. import (
  3. "github.com/casbin/casbin/v2"
  4. "github.com/gin-gonic/gin"
  5. "github.com/go-admin-team/go-admin-core/sdk"
  6. "github.com/go-admin-team/go-admin-core/sdk/api"
  7. )
  8. func LoadPolicy(c *gin.Context) (*casbin.SyncedEnforcer, error) {
  9. log := api.GetRequestLogger(c)
  10. if err := sdk.Runtime.GetCasbinKey(c.Request.Host).LoadPolicy(); err == nil {
  11. return sdk.Runtime.GetCasbinKey(c.Request.Host), err
  12. } else {
  13. log.Errorf("casbin rbac_model or policy init error, %s ", err.Error())
  14. return nil, err
  15. }
  16. }