Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

casbin/mysql-adapter

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.