A Casbin adapter based on the GoFrame framework. With this library, Casbin can load policies from or save policies to databases supported by GoFrame. This adapter supports or plans to support all Casbin adapter interfaces.
Based on GoFrame database driver support, currently supported databases include:
- MySQL
- PostgreSQL
- Other databases supported by GoFrame
Both model and dao are generated by gf gen, conforming to GoFrame's ORM specifications.
- This adapter implements all Casbin Adapter interfaces, but functionality is still being tested.
Please complete GoFrame database configuration first and import relevant driver packages, such as:
import _ "github.com/gogf/gf/contrib/drivers/mysql/v2"
go get github.com/yclw/gf-casbin-adapterimport (
gfadapter "github.com/yclw/gf-casbin-adapter"
"github.com/casbin/casbin/v2"
"github.com/casbin/casbin/v2/model"
)// Create Adapter
adapter, err := gfadapter.NewAdapter()// Create model according to Casbin requirements
// Create enforcer using model and adapter
enforcer, err := casbin.NewEnforcer(model, adapter)- Ensure GoFrame database configuration is correct.
CREATE TABLE casbin_rule (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
ptype VARCHAR(100) DEFAULT '' NOT NULL,
v0 VARCHAR(100) DEFAULT '' NOT NULL,
v1 VARCHAR(100) DEFAULT '' NOT NULL,
v2 VARCHAR(100) DEFAULT '' NOT NULL,
v3 VARCHAR(100) DEFAULT '' NOT NULL,
v4 VARCHAR(100) DEFAULT '' NOT NULL,
v5 VARCHAR(100) DEFAULT '' NOT NULL,
INDEX idx_ptype (ptype),
INDEX idx_v0 (v0),
INDEX idx_v1 (v1),
INDEX idx_v2 (v2),
INDEX idx_v3 (v3),
INDEX idx_v4 (v4),
INDEX idx_v5 (v5),
) COMMENT 'Casbin';- Casbin Official Documentation
- GoFrame Official Documentation
- Casbin Chinese Documentation
- GoFrame Chinese Documentation
- Casbin GitHub
- hailaz/gf-casbin-adapter
- casbin/gorm-adapter
- casbin/xorm-adapter
This project is licensed under the Apache 2.0 License. See the LICENSE file for details.
Issues and Pull Requests are welcome to improve this project.