Skip to content

Latest commit

 

History

History
48 lines (33 loc) · 1.56 KB

README.md

File metadata and controls

48 lines (33 loc) · 1.56 KB

MySQL Adapter Build Status Coverage Status Godoc

MySQL Adapter is the MySQL DB adapter for Casbin. With this library, Casbin can load policy from MySQL or save policy to it.

Installation

go get github.com/casbin/mysql-adapter

Simple Example

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()
}

Getting Help

License

This project is under Apache 2.0 License. See the LICENSE file for the full license text.