Google Protocol Buffers adapter for Casbin

Clone this repo:

Branches

  1. 2ad91ee Add empty auto-save functions. by Yang Luo · 9 years ago master
  2. aab3dea Rename ProtobufAdapter to Adapter. by Yang Luo · 9 years ago
  3. cd4afdc Comment on the trick in test. by Yang Luo · 9 years ago
  4. 850e8e9 Fix typo in README. by Yang Luo · 9 years ago
  5. ebac896 Add Travis CI and coverage. by Yang Luo · 9 years ago

Protobuf Adapter Build Status Coverage Status Godoc

Protobuf Adapter is the Google Protocol Buffers adapter for Casbin. With this library, Casbin can load policy from Protocol Buffers or save policy to it.

Installation

go get github.com/casbin/protobuf-adapter

Simple Example

package main

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

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

Getting Help

License

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