JSON adapter for Casbin
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
examples
.gitignore
.travis.yml
LICENSE
README.md
adapter.go
adapter_test.go

README.md

JSON Adapter Build Status Coverage Status Godoc

JSON Adapter is the JSON (JavaScript Object Notation) adapter for Casbin. With this library, Casbin can load policy from JSON string or save policy to it.

Installation

go get github.com/casbin/json-adapter

Simple Example

package main

import (
	"github.com/casbin/casbin"
	"github.com/casbin/json-adapter"
)

func main() {
	// Initialize a JSON adapter and use it in a Casbin enforcer:
	b := []byte{} // b stores Casbin policy in JSON bytes.
	a := jsonadapter.NewAdapter(&b) // Use b as the data source. 
	e := casbin.NewEnforcer("examples/rbac_model.conf", a)
	
	// Load the policy from JSON bytes b.
	e.LoadPolicy()
	
	// Check the permission.
	e.Enforce("alice", "data1", "read")
	
	// Modify the policy.
	// e.AddPolicy(...)
	// e.RemovePolicy(...)
	
	// Save the policy back to JSON bytes b.
	e.SavePolicy()
}

Getting Help

License

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