Documentation ¶
Overview ¶
Package can implements basic role-based permissions for golang - controlling who can.Do certain actions for a given database table.
Index ¶
- Constants
- func Authorise(role int64, v Verb, id string)
- func AuthoriseOwner(role int64, v Verb, id string)
- func Connect(r Resource, u User) error
- func Create(r Resource, u User) error
- func Destroy(r Resource, u User) error
- func Do(v Verb, r Resource, u User) error
- func List(r Resource, u User) error
- func Manage(r Resource, u User) error
- func Show(r Resource, u User) error
- func Update(r Resource, u User) error
- type Ability
- type Resource
- type User
- type Verb
Constants ¶
const ( ManageResource = iota ListResource // Does not check ownership CreateResource // Does not check ownership ConnectResource ShowResource UpdateResource DestroyResource )
Verbs used to authorise actions on resources. Manages allows any action on a resource, and all verbs after Creates check ownership of the resource with OwnedBy().
const (
Anything = "*" // Allow actions on any resource
)
Resource identifier used to short-circuit checks on resource identity in conjuction with ManageResource
Variables ¶
This section is empty.
Functions ¶
func Authorise ¶
Authorise adds this ability to the list of abilities for this role. Usage: can.Authorise(role.Admin, can.ManageResource, "pages")
func AuthoriseOwner ¶
AuthoriseOwner adds this ability to the list of abilities for this role for resources owned by this user. Usage: can.AuthoriseOwner(role.Reader, can.ShowResource, "pages")
Types ¶
type Ability ¶
type Ability struct {
// contains filtered or unexported fields
}
Ability represents an authorisation for an action for a given role
func (*Ability) CheckOwner ¶
CheckOwner returns true if this ability should check ownership
type Resource ¶
type Resource interface { OwnedBy(int64) bool // for ownership check, passed a UserID ResourceID() string // for check against abilities registered on this resource }
Resource defines the interface for resources