auth

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: Apache-2.0 Imports: 5 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// ReadPerm the permission of read
	ReadPerm = "r"
	// WritePerm the permission of write
	WritePerm = "w"
	// ExecutePerm the permission of execute
	ExecutePerm = "x"
	// DefaultPerm the default permission
	DefaultPerm = ReadPerm
	// FullPerm the permission of read, write and execute
	FullPerm = "rwx"
)

Variables

This section is empty.

Functions

func ParseStringUsers

func ParseStringUsers(users []*User) (userStr string, err error)

ParseStringUsers parse user list to user string

Types

type Perm added in v0.3.0

type Perm string

Perm the basic permission info

func ToPerm added in v0.3.0

func ToPerm(perm string) (p Perm)

ToPerm convert a perm string to Perm

func ToPermWithDefault added in v0.3.0

func ToPermWithDefault(perm string, defaultPerm string) (p Perm)

ToPermWithDefault convert a perm string to Perm defaultPerm if the perm is empty, replace with the defaultPerm

func (Perm) CheckTo added in v0.3.0

func (p Perm) CheckTo(t Perm) bool

CheckTo check the target permission whether accord with current permission if the current permission is invalid, return false always

func (Perm) IsValid added in v0.3.0

func (p Perm) IsValid() bool

IsValid is a valid permission or not

func (Perm) R added in v0.3.0

func (p Perm) R() bool

R have the permission to read or not

func (Perm) String added in v0.3.0

func (p Perm) String() string

String return perm string

func (Perm) W added in v0.3.0

func (p Perm) W() bool

W have the permission to write or not

func (Perm) X added in v0.3.0

func (p Perm) X() bool

X have the permission to execute or not

type SessionUser

type SessionUser struct {
	UserId   int
	UserName string
	Password string
	Perm     Perm
}

SessionUser the login user info that is stored in session

func MapperToSessionUser

func MapperToSessionUser(user *User) *SessionUser

MapperToSessionUser convert User to SessionUser

type User

type User struct {
	// contains filtered or unexported fields
}

User a login user info

func GetAnonymousUser added in v0.6.2

func GetAnonymousUser() *User

GetAnonymousUser get an anonymous user

func NewUser

func NewUser(userId int, userName string, password string, perm string) (*User, error)

NewUser create a new user

func ParseUsers

func ParseUsers(userStr string) (users []*User, err error)

ParseUsers parse users string to User List For example: user1|password1|rwx,user2|password2|rwx

func RandomUser

func RandomUser(count, userLen, pwdLen int, perm string) ([]*User, error)

RandomUser generate some user with random username and password count is user count you want userLen is the length of random username, max length is 20 pwdLen is the length of random password, max length is 20 perm is the default permission of every random user, like 'rwx'

func (*User) Password

func (user *User) Password() string

Password return user password

func (*User) Perm added in v0.3.0

func (user *User) Perm() Perm

Perm return user permission

func (*User) String

func (user *User) String() string

String return format user info

func (*User) UserId

func (user *User) UserId() int

UserId return user id

func (*User) UserName

func (user *User) UserName() string

UserName return username

Jump to

Keyboard shortcuts

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