ACL is a simple but powerful Access Control List manager
go get -u github.com/txgruppi/acl-go
You should not ignore the errors returned by the methods
package main
import (
"fmt"
"github.com/txgruppi/acl-go"
"github.com/txgruppi/acl-go/driver/memory"
)
func main() {
driver := memory.NewDriver()
// Driver can be directly used as ACL managers
var manager acl.ACL = driver
// Set the default policy as Deny
acl.SetDefaultPolicy(acl.Deny)
// Get some users
userCEO, _ := acl.GetActor("userCEO_UUID")
userDeveloper, _ := acl.GetActor("userDeveloper_UUID")
// Get some actions
accessBackAccount, _ := acl.GetAction("accessBackAccount")
accessProductionServer, _ := acl.GetAction("accessProductionServer")
// Set rules
acl.Set(userCEO, accessBackAccount, acl.Allow)
acl.Set(userDeveloper, accessProductionServer, acl.Allow)
// Check using the ACL manager
allowed, _ := acl.IsAllowed(userCEO, accessBackAccount)
fmt.Println(allowed) // true
allowed, _ = acl.IsAllowed(userDeveloper, accessBackAccount)
fmt.Println(allowed) // false
// Check using the Actor or Action struct
allowed, _ := userCEO.IsAllowed(accessProductionServer)
fmt.Println(allowed) // false
allowed, _ = accessProductionServer.Allows(userDeveloper)
fmt.Println(allowed) // true
}
go get -u -t github.com/txgruppi/acl-go
cd $GOPATH/src/github.com/txgruppi/acl-go
go test ./...
MIT