Skip to content

tclairet/json-adapter

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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/v2"
	"github.com/casbin/json-adapter/v2"
)

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.

About

JSON adapter for Casbin

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%