Skip to content

h4ckedneko/casbin-httpfs

Repository files navigation

Casbin HTTP FileSystem Adapter

GoDoc Reference Latest Version License Name Build Status Coverage Status Report Card Status

Package casbin-httpfs is a convenient http.FileSystem adapter for Casbin v2. It enables Casbin to load policy and model from anything that implements the http.FileSystem interface.

Installation

Make sure you have a working Go workspace, then:

go get github.com/h4ckedneko/casbin-httpfs

For updating to latest stable release, do:

go get -u github.com/h4ckedneko/casbin-httpfs

Usage

Here is a basic example for this package:

package main

import (
	"net/http"

	"github.com/casbin/casbin/v2"
	casbinfs "github.com/h4ckedneko/casbin-httpfs"
)

var fs http.FileSystem = http.Dir("/")

func main() {
	// Initialize a new adapter instance.
	adapter := casbinfs.NewAdapter(fs, "/path/to/policy.csv")

	// Initialize a new enforcer instance by passing the adapter.
	enforcer, _ := casbin.NewEnforcer("/path/to/model.conf", adapter)

	// Start checking for permissions.
	enforcer.Enforce("alice", "data1", "read")
}

License

MIT © Lyntor Paul Figueroa. See LICENSE for full license text.