template

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PermBAC = Perms{
	PermRoot,
}

PermBAC is the instance of the PermBAC access control model.

View Source
var PermRoot = Perm{
	Name: "*",
	Desc: "Has all permissions",
}

PermRoot Has all permissions

Name: *

Functions

This section is empty.

Types

type Perm

type Perm struct {
	Name string `json:"name" param:"name" query:"name" form:"name" xml:"name" csv:"name"`
	Desc string `json:"desc" param:"desc" query:"desc" form:"desc" xml:"desc" csv:"desc"`
}

Perm represents a permission.

Can be associated directly with a user or can be associated with a role that is then associated with a user, it's up to you how you want to implement it.

func (Perm) Check

func (p Perm) Check(permsToCheck ...string) bool

Check checks if a permission is contained in a list of permissions.

Also returns true if the root permission is found.

func (Perm) String

func (p Perm) String() string

String returns a string representation of a permission.

It returns the name of the permission.

type Perms

type Perms []Perm

Perms is a slice of permissions

Can be associated directly with a user or can be associated with a role that is then associated with a user, it's up to you how you want to implement it.

func (Perms) CheckAllPerms

func (p Perms) CheckAllPerms(
	permsToCheck []string,
	requiredPerms []Perm,
) bool

CheckAllPerms checks if a list of user perm names are contained in another list of required perms.

Returns true if all required perms are contained in the user perms list.

Also returns true if the root permission is found.

func (Perms) CheckAnyPerm

func (p Perms) CheckAnyPerm(
	permsToCheck []string,
	requiredPerms []Perm,
) bool

CheckAnyPerm checks if any of the required perms are contained in the user perms list.

Returns true if any of the required perms is found in the user perms list.

Also returns true if the root permission is found.

func (Perms) CheckPerm

func (p Perms) CheckPerm(
	permsToCheck []string,
	requiredPerm Perm,
) bool

CheckPerm checks if a list of user perm names contains a required perm.

Returns true if the required perm is contained.

Also returns true if the root permission is found.

func (Perms) GetPermByName

func (p Perms) GetPermByName(name string) (Perm, bool)

GetPermByName returns the Perm with the given name and a boolean indicating if it was found.

func (Perms) PermNames

func (p Perms) PermNames() []string

PermNames returns all permission names in a slice that can be iterated or stored in a database or other storage and then checked using the other methods.

func (Perms) String

func (p Perms) String() string

String returns a string representation of a list of permissions.

It returns a string of permission names separated by commas.

Jump to

Keyboard shortcuts

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