Merge pull request #1 from pjediny/casbin-v2-go-mod Add support for Casbin v2.0.0
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.
go get github.com/casbin/json-adapter
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() }
This project is under Apache 2.0 License. See the LICENSE file for the full license text.