Casbin ZORM Adapter is the ZORM Adapter for Casbin. With this library, Casbin can load policy from ZORM supported database or save policy to it.
Based on ZORM Drivers Support, the current supported databases are:
- mysql: github.com/go-sql-driver/mysql
- pgsql: github.com/lib/pq
- dm: gitee.com/chunanyong/dm
- oracle: github.com/sijms/go-ora/v2
- kingbase: official driver(authorization required)
- shentong: official driver(authorization required)
- gbase: ODBC
- clickhouse: github.com/mailru/go-clickhouse/v2
go get -u github.com/workits/casbin-zorm-adapter
dbConfig := &zorm.DataSourceConfig{
DSN: "root:password@tcp(127.0.0.1:3306)/casbin?charset=utf8&parseTime=true&loc=Local",
DriverName: "mysql",
Dialect: "mysql",
// ... more configurations
}
dbDao, err := zorm.NewDBDao(dbConfig)
if err != nil {
panic(err)
}
a := NewAdapter(dbDao) // you can also use: NewAdapter(dbDao, "your_casbin_rule_table")
e, err := casbin.NewEnforcer("examples/rbac_model.conf", a)
if err != nil {
panic(err)
}
// ... do your things
Special thanks to Casbin Organization, they provide a superb authorization library.
Special thanks to ZORM, a lightweight ORM.
And SQLX Adapter@memwey, which testcase I used.
This project is under Apache 2.0 License. See the LICENSE file for the full license text.