rethinkadapter

package module
v0.0.0-...-9d5b583 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 27, 2019 License: MIT Imports: 5 Imported by: 0

README

RethinkDB Adapter

RethinkDB Adapter is the Rethink DB adapter for Casbin. With this library, Casbin can load policy from RethinkDB or save policy to it.

Installation

go get github.com/adityapandey9/rethinkdb-adapter

Simple Example

package main

import (
    	"os"
    	r "gopkg.in/gorethink/gorethink.v3"
	"github.com/casbin/casbin"
	"github.com/adityapandey9/rethinkdb-adapter"
)

func getConnect() r.QueryExecutor {
	url := os.Getenv("RETHINKDB_URL") //Get the Rethinkdb url from system env

	if url == "" {
		url = "localhost:28015"
	}

	session, _ := r.Connect(r.ConnectOpts{
		Address: url,
	})

	return session
}

func main() {
	// Initialize a RethinkDB get session, add it to 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.
  	session := getConnect()
	a := rethinkadapter.NewAdapter(session) // Your RethinkDB Session. 
	
	e := casbin.NewEnforcer("examples/casbinmodel.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 MIT License. See the LICENSE file for the full license text.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAdapter

func NewAdapter(Sessionvar r.QueryExecutor, database, table string) persist.Adapter

NewAdapter is the constructor for adapter.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL