Documentation ¶
Index ¶
- Variables
- func NewError(err error, kind Kind) error
- type Error
- type Kind
- type Model
- type PersonalAccessToken
- type PersonalAccessTokenCreateResponse
- type PersonalAccessTokenResponse
- type PersonalAccessTokens
- type PersonalAccessTokensResponse
- type Ref
- type Role
- type Task
- type TaskResponse
- type TaskSearchParams
- type Tasks
- type TasksResponse
- type User
- func (u *User) AddRole(user *User, role Role) error
- func (u *User) AdminResponse() *UserAdminResponse
- func (u *User) Ban(user *User) error
- func (u *User) HasRoleOrHigher(role Role) bool
- func (u *User) Lock(user *User) error
- func (u *User) Login() ([]byte, []byte, error)
- func (u *User) Logout()
- func (u *User) Ref() *UserRef
- func (u *User) Refresh() ([]byte, []byte, error)
- func (u *User) RemoveRole(user *User, role Role) error
- func (u *User) Response() *UserResponse
- func (u *User) SetPassword(s string) error
- func (u *User) Unban(user *User) error
- func (u *User) Unlock(user *User) error
- func (u *User) ValidatePassword(s string) error
- func (u *User) ValidateRefreshToken(s string) error
- type UserAdminResponse
- type UserRef
- type UserResponse
- type UserSearchParams
- type Users
- type UsersAdminResponse
- type UsersResponse
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrAdminRoleRequired = errors.New("admin or greater role required") ErrBanSelf = errors.New("cannot ban self") ErrBanExist = errors.New("user already banned") ErrBanMorePrivileged = errors.New("cannot ban user with higher permissions") ErrUnbanSelf = errors.New("cannot unban self") ErrUnbanExist = errors.New("user already unbanned") ErrUnbanMorePrivileged = errors.New("cannot unban user with higher permissions") ErrLockSelf = errors.New("cannot lock self") ErrLockExist = errors.New("user already locked") ErrLockMorePrivileged = errors.New("cannot lock user with higher permissions") ErrUnlockSelf = errors.New("cannot unlock self") ErrUnlockExist = errors.New("user already unlocked") ErrUnlockMorePrivileged = errors.New("cannot unlock user with higher permissions") ErrRoleSelf = errors.New("cannot modify own roles") ErrRoleAddExist = errors.New("user already has role") ErrRoleAddMorePrivileged = errors.New("cannot add a more privileged role") ErrRoleRemoveNotExist = errors.New("user doesn't have role") ErrRoleRemoveMorePrivileged = errors.New("cannot remove a more privileged role") )
View Source
var ErrExpiresAtPast = errors.New("expires_at cannot be in the past")
Functions ¶
Types ¶
type Model ¶
type Model struct { Id string `bson:"id"` CreatedAt *time.Time `bson:"created_at"` CreatedBy any `bson:"created_by"` DeletedAt *time.Time `bson:"deleted_at"` DeletedBy any `bson:"deleted_by"` UpdatedAt *time.Time `bson:"updated_at"` UpdatedBy any `bson:"updated_by"` }
Model is the base model for all models. NewModel should be used unless you know what you're doing.
type PersonalAccessToken ¶
type PersonalAccessToken struct { Id string `bson:"id"` CreatedAt *time.Time `bson:"created_at"` ExpiresAt *time.Time `bson:"expires_at"` IsRevoked bool `bson:"is_revoked"` Name string `bson:"name"` Token string `bson:"token"` UserId string `bson:"user_id"` }
func NewPersonalAccessToken ¶
func NewPersonalAccessToken(userId string, name string, expiresAt string) (*PersonalAccessToken, error)
func (*PersonalAccessToken) CreateResponse ¶
func (pat *PersonalAccessToken) CreateResponse() *PersonalAccessTokenCreateResponse
func (*PersonalAccessToken) Encrypt ¶
func (pat *PersonalAccessToken) Encrypt() error
func (*PersonalAccessToken) Response ¶
func (pat *PersonalAccessToken) Response() *PersonalAccessTokenResponse
func (*PersonalAccessToken) Validate ¶
func (pat *PersonalAccessToken) Validate(s string) error
type PersonalAccessTokenCreateResponse ¶
type PersonalAccessTokenCreateResponse struct { PersonalAccessTokenResponse Token string `json:"token"` }
type PersonalAccessTokens ¶
type PersonalAccessTokens []PersonalAccessToken
func (PersonalAccessTokens) Response ¶
func (pats PersonalAccessTokens) Response() *PersonalAccessTokensResponse
type PersonalAccessTokensResponse ¶
type PersonalAccessTokensResponse struct {
Tokens []PersonalAccessTokenResponse `json:"personal_access_tokens"`
}
type Ref ¶
type Ref struct {
Id string `json:"id" bson:"id"`
}
Ref is a reference to another document.
type Task ¶
type Task struct { *Model `bson:",inline"` Completed bool `bson:"completed"` CompletedAt *time.Time `bson:"completed_at"` CompletedBy any `bson:"completed_by"` Title string `bson:"title"` }
func (*Task) Incomplete ¶
func (t *Task) Incomplete()
func (*Task) MarshalBSON ¶
func (*Task) Response ¶
func (t *Task) Response() *TaskResponse
func (*Task) UnmarshalBSON ¶
type TaskResponse ¶
type TaskResponse struct { Id string `json:"id"` Completed bool `json:"completed"` CompletedAt *time.Time `json:"completed_at"` CompletedBy *UserRef `json:"completed_by"` CreatedAt *time.Time `json:"created_at"` CreatedBy *UserRef `json:"created_by"` DeletedAt *time.Time `json:"-"` DeletedBy *UserRef `json:"-"` Title string `json:"title"` UpdatedAt *time.Time `json:"updated_at"` UpdatedBy *UserRef `json:"updated_by"` }
type TaskSearchParams ¶
type TasksResponse ¶
type TasksResponse struct {
Tasks []TaskResponse `json:"tasks"`
}
type User ¶
type User struct { *Model `bson:",inline"` BannedAt *time.Time `bson:"banned_at"` BannedBy any `bson:"banned_by"` Bio string `bson:"bio"` Email string `bson:"email"` IsBanned bool `bson:"is_banned"` IsLocked bool `bson:"is_locked"` LastLoginAt *time.Time `bson:"last_login_at"` LastLogoutAt *time.Time `bson:"last_logout_at"` LastRefreshAt *time.Time `bson:"last_refresh_at"` LockedAt *time.Time `bson:"locked_at"` LockedBy any `bson:"locked_by"` Name string `bson:"name"` Password string `bson:"password"` RefreshToken string `bson:"refresh_token"` Roles []string `bson:"roles"` UnbannedAt *time.Time `bson:"unbanned_at"` UnbannedBy any `bson:"unbanned_by"` UnlockedAt *time.Time `bson:"unlocked_at"` UnlockedBy any `bson:"unlocked_by"` Username string `bson:"username"` }
func (*User) AdminResponse ¶
func (u *User) AdminResponse() *UserAdminResponse
func (*User) HasRoleOrHigher ¶
func (*User) Response ¶
func (u *User) Response() *UserResponse
func (*User) SetPassword ¶
func (*User) ValidatePassword ¶
func (*User) ValidateRefreshToken ¶
type UserAdminResponse ¶
type UserResponse ¶
type UserSearchParams ¶
type Users ¶
type Users []User
func (Users) AdminResponse ¶
func (users Users) AdminResponse() *UsersAdminResponse
func (Users) Response ¶
func (users Users) Response() *UsersResponse
type UsersAdminResponse ¶
type UsersAdminResponse struct {
Users []UserAdminResponse `json:"users"`
}
type UsersResponse ¶
type UsersResponse struct {
Users []UserResponse `json:"users"`
}
Click to show internal directories.
Click to hide internal directories.