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: *xormadapter.Adapter is not persist.Adapter: missing method LoadPolicy #22

Closed
mrchar opened this issue Dec 11, 2019 · 9 comments
Assignees
Labels

Comments

@mrchar
Copy link
Contributor

mrchar commented Dec 11, 2019

package main

import (
	"github.com/casbin/casbin/v2"
	_ "github.com/go-sql-driver/mysql"

	"github.com/casbin/xorm-adapter"
)

func main() {
	// Initialize a Xorm adapter and use it in a Casbin enforcer:
	// The adapter will use the MySQL database named "casbin".
	// If it doesn't exist, the adapter will create it automatically.
	a, _ := xormadapter.NewAdapter("mysql", "mysql_username:mysql_password@tcp(127.0.0.1:3306)/") // Your driver and data source. 

	// Or you can use an existing DB "abc" like this:
	// The adapter will use the table named "casbin_rule".
	// If it doesn't exist, the adapter will create it automatically.
	// a := xormadapter.NewAdapter("mysql", "mysql_username:mysql_password@tcp(127.0.0.1:3306)/abc", true)

	e, _ := casbin.NewEnforcer("examples/rbac_model.conf", a)
	
	// Load the policy from DB.
	e.LoadPolicy()
	
	// Check the permission.
	e.Enforce("alice", "data1", "read")
	
	// Modify the policy.
	// e.AddPolicy(...)
	// e.RemovePolicy(...)
	
	// Save the policy back to DB.
	e.SavePolicy()
}
panic: interface conversion: *xormadapter.Adapter is not persist.Adapter: missing method LoadPolicy

goroutine 1 [running]:
github.com/casbin/casbin/v2.NewEnforcer(0xc00012bf00, 0x2, 0x2, 0x1c, 0x0, 0x0)
        /home/char/go/pkg/mod/github.com/casbin/casbin/v2@v2.1.2/enforcer.go:84 +0x143
main.main()
        /home/char/Documents/nova/dingyue/authorization/test/adapter/xorm.go:23 +0xde
@mrchar
Copy link
Contributor Author

mrchar commented Dec 11, 2019

go.mod

module authorization

go 1.13

require (
	github.com/casbin/casbin v1.9.1
	github.com/casbin/casbin/v2 v2.1.2
	github.com/casbin/xorm-adapter v1.0.0
	github.com/go-sql-driver/mysql v1.4.1
	github.com/go-xorm/xorm v0.7.9 // indirect
	google.golang.org/appengine v1.6.5 // indirect
)

@mrchar
Copy link
Contributor Author

mrchar commented Dec 11, 2019

I guess it's because xorm-adapter v2's go.mod incorrectly declares the module as xorm-adapter.

@hsluoyz
Copy link
Member

hsluoyz commented Dec 11, 2019

Can you make a PR to fix it?

@hsluoyz hsluoyz self-assigned this Dec 11, 2019
@hsluoyz hsluoyz added the bug label Dec 11, 2019
@hsluoyz
Copy link
Member

hsluoyz commented Dec 11, 2019

@nodece

@hsluoyz hsluoyz mentioned this issue Dec 12, 2019
@fengjihua
Copy link

do NOT work, fix please

import "github.com/casbin/xorm-adapter/v2"

cannot load github.com/casbin/xorm-adapter/v2: cannot find module providing package github.com/casbin/xorm-adapter/v2

@hsluoyz
Copy link
Member

hsluoyz commented Jan 8, 2020

@fengjihua can you make a fix PR?

@mrchar
Copy link
Contributor Author

mrchar commented Jan 10, 2020

@hsluoyz can not fix with commit, maybe you should add a new tag like 2.0.1.

@hsluoyz
Copy link
Member

hsluoyz commented Jan 10, 2020

Released: https://github.com/casbin/xorm-adapter/releases/tag/v2.0.1

@hsluoyz hsluoyz closed this as completed Jan 10, 2020
@fengjihua
Copy link

Released: https://github.com/casbin/xorm-adapter/releases/tag/v2.0.1

work like a charm! awesome!

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