GRBAC is a fast Golang library which provides a role-based access control.
The project is written with a focus on performance, minimalism, and a small number of abstractions.
Run this command
go get -v github.com/deterok/grbac
or
go get -v gopkg.in/deterok/grbac.v1
// Create User role
roleU := NewRole("User")
// Add the permissions to the User role
roleU.Permit("CreateMsg")
roleU.Permit("ReadMsg")
// Create Admin role
roleA := NewRole("Admin")
// Add the permissions to the Admin role
roleA.Permit("EditMsg")
roleA.Permit("DelMsg")
// Set the parent
roleA.SetParent(roleU)
// Check the permissions
if roleA.IsAllowed("CreateMsg", "ReadMsg", "EditMsg", "DelMsg") {
fmt.Println("All permissions are allowed for the Admin role!")
}
More examples in godoc
Pull requests and stars are welcome. For bugs and feature requests, please create an issue.
Copyright (C) 2016, Vadim Suharnikov. Released under the MIT license.