fix: policies need to be added after

This commit is contained in:
Derrick Hammer 2024-01-15 22:53:12 -05:00
parent 212832eda1
commit 87ebf5012b
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 5 additions and 4 deletions

View File

@ -18,15 +18,16 @@ func GetCasbin(logger *zap.Logger) *casbin.Enforcer {
a := NewPolicyAdapter(logger) a := NewPolicyAdapter(logger)
_ = a.AddPolicy("admin", "/admin", []string{"GET"})
_ = a.AddPolicy("admin", "/admin", []string{"POST"})
_ = a.AddPolicy("admin", "/admin", []string{"DELETE"})
e, err := casbin.NewEnforcer(m, a) e, err := casbin.NewEnforcer(m, a)
if err != nil { if err != nil {
logger.Fatal("Failed to create casbin enforcer", zap.Error(err)) logger.Fatal("Failed to create casbin enforcer", zap.Error(err))
} }
// Add policies after creating the enforcer
_ = a.AddPolicy("admin", "/admin", []string{"GET"})
_ = a.AddPolicy("admin", "/admin", []string{"POST"})
_ = a.AddPolicy("admin", "/admin", []string{"DELETE"})
return e return e
} }