Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic: interface conversion: *beegoormadapter.Adapter is not persist.Adapter: missing method LoadPolicy #687

Closed
smp12345 opened this issue Jan 26, 2021 · 3 comments
Assignees
Labels

Comments

@smp12345
Copy link

smp12345 commented Jan 26, 2021

What's your scenario? What do you want to achieve?

When I use the Beego ORM adapter, refer to the GitHub sample code and report the following error

Your model:

[request_definition]
r = sub, obj, act

[policy_definition]
p = sub, obj, act,eft

[role_definition]
g = _, _

[policy_effect]
e = some(where (p.eft == allow)) && !some(where (p.eft == deny))

[matchers]
m = g(r.sub, p.sub) && my_func(r.obj, p.obj) && r.act == p.act

Your policy:

"alice", "data1", "read"

test code

func main() {
	// Initialize a Beego ORM adapter and use it in a Casbin enforcer:
	a := beegoormadapter.NewAdapter( "mysql", "root:xxxx@tcp(127.0.0.1:3306)/casbin",true) // Your driver and data source.

	e, err := casbin.NewEnforcer("model.conf", a)
	if err != nil {
		log.Fatalln(err)
	}
	// Check the permission.
	e.Enforce("alice", "data1", "read")

	// Modify the policy.
	// e.AddPolicy(...)
	// e.RemovePolicy(...)

	// Save the policy back to DB.
	e.SavePolicy()
}

Frame error:

panic: interface conversion: *beegoormadapter.Adapter is not persist.Adapter: missing method LoadPolicy

goroutine 1 [running]:
github.com/casbin/casbin/v2.NewEnforcer(0xc0000c9f58, 0x2, 0x2, 0x29, 0xc0000c9f3f, 0x1)
        D:/gopath/go/pkg/mod/github.com/casbin/casbin/v2@v2.20.2/enforcer.go:94 +0x234
main.main()
        D:/go-project/ec/test/test.go:15 +0xee

@nodece
Copy link
Member

nodece commented Jan 26, 2021

@smp12345 you should import the beegoormadapter "github.com/casbin/beego-orm-adapter/v2".

@nodece nodece closed this as completed Jan 26, 2021
@smp12345
Copy link
Author

That's done, thank you

@hsluoyz
Copy link
Member

hsluoyz commented Jan 26, 2021

README fixed: casbin/beego-orm-adapter@a77df7a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants