Set up default protection ruleset for default and release branches
MySQL Adapter is the MySQL DB adapter for Casbin. With this library, Casbin can load policy from MySQL or save policy to it.
go get github.com/casbin/mysql-adapter
package main import ( "github.com/casbin/casbin" "github.com/casbin/mysql-adapter" ) func main() { // Initialize a MySQL adapter and use it in a Casbin enforcer: // The adapter will use the database named casbin. // If it doesn't exist, the adapter will create it automatically. a := mysqladapter.NewAdapter("mysql", "mysql_username:mysql_password@tcp(127.0.0.1:3306)/") // Your MySQL driver and data source. 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() }
This project is under Apache 2.0 License. See the LICENSE file for the full license text.