Fail to LoadPolicy
chirichan opened this issue · comments
I use casbin-pg-adapter , have an error msg.
this is error msg:
PS D:\Documents\test> go run .\main.go
2021/11/29 12:42:34 错误 #42703 字段 casbin_rule.p_type 不存在
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x10 pc=0x8b110d]
goroutine 1 [running]:
github.com/casbin/casbin/v2.(*Enforcer).LoadPolicy(0x0)
C:/Users/Administrator/go/pkg/mod/github.com/casbin/casbin/v2@v2.39.1/enforcer.go:284 +0x4d
main.main()
D:/Documents/test/main.go:24 +0x105
exit status 2
when i change the field ptype
to p_type
, it's ok.
PS D:\Documents\test> go run .\main.go
2021/11/29 12:52:49 true
this is my enviorment:
go 1.17.2
casbin v2.39.1
casbin-pg-adapter v1.0.3
PostgreSQL 12.8
this is my code:
package main
import (
"log"
pgadapter "github.com/casbin/casbin-pg-adapter"
"github.com/casbin/casbin/v2"
)
func main() {
url := "postgresql://postgres:111111@localhost:5432/casbin?sslmode=disable"
a, err := pgadapter.NewAdapter(url)
if err != nil {
log.Println(err)
}
e, err := casbin.NewEnforcer("model.conf", a)
if err != nil {
log.Println(err)
}
// Load the policy from DB.
err = e.LoadPolicy()
if err != nil {
log.Println(err)
}
// Check the permission.
b1, err := e.Enforce("alice", "data1", "write")
if err != nil {
log.Println(err)
}
log.Println(b1)
// Save the policy back to DB.
e.SavePolicy()
}
@tangyang9464 @closetool @sagilio