rbac

package
v1.0.23 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: MIT Imports: 5 Imported by: 8

Documentation

Index

Constants

View Source
const (
	ActionLogin          = "login"
	ActionSignUp         = "sign-up"
	ActionResetPassword  = "reset-password"
	ActionChangePassword = "change-password"
	ActionSendCode       = "send-code"
)

定义几种常用的授权动作

View Source
const (
	MechanismPassword = "password"
	MechanismEmail    = "email"
	MechanismPhone    = "phone"
)

定义几种常用的验证机制

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthDTO

type AuthDTO struct {
	BaseDTO

	Action    string      `json:"action"` // 如果为空,表示这条信息仅用于认证
	Mechanism string      `json:"mechanism"`
	Account   string      `json:"account"`
	Secret    lang.Base64 `json:"secret"`

	Parameters map[string]string `json:"parameters"` // 其它扩展属性
}

AuthDTO 用于登录认证

type AuthService

type AuthService interface {
	Handle(c context.Context, a []*AuthDTO) error
}

AuthService 是针对 AuthDTO 的服务

type AuthVO

type AuthVO struct {
	BaseVO

	Auth []*AuthDTO `json:"auth"` // 用于验证的信息
}

AuthVO ...

type BaseDTO

type BaseDTO struct {
	UUID lang.UUID `json:"uuid"`

	CreatedAt lang.Time `json:"created_at"`
	UpdatedAt lang.Time `json:"updated_at"`
	DeletedAt lang.Time `json:"deleted_at"`

	Owner   UserID `json:"owner"`
	Creator UserID `json:"creator"`
	Updater UserID `json:"updater"`
}

BaseDTO 是基本的 DTO

type BaseVO

type BaseVO struct {
	Status     int         `json:"status"`
	Message    string      `json:"message"`
	Error      string      `json:"error"`
	Time       time.Time   `json:"time"`
	Timestamp  lang.Time   `json:"timestamp"`
	Pagination *Pagination `json:"pagination"`
}

BaseVO 是通用的基本 VO 结构

func (*BaseVO) GetVO

func (inst *BaseVO) GetVO() *BaseVO

GetVO 实现 BaseGetter

type EmailAddressDTO added in v1.0.5

type EmailAddressDTO struct {
	ID EmailAddressID `json:"id"`

	BaseDTO

	Address string `json:"address"`
}

EmailAddressDTO ...

type EmailAddressID added in v1.0.5

type EmailAddressID int64

EmailAddressID ...

type EmailAddressQuery added in v1.0.5

type EmailAddressQuery struct {
	Pagination Pagination
}

EmailAddressQuery 查询参数

type EmailAddressService added in v1.0.5

EmailAddressService ...

type Pagination

type Pagination struct {
	Page  int64 `json:"page"`  // 页码, first=1
	Size  int   `json:"size"`  // 页大小
	Total int64 `json:"total"` // 所有页面的条目总数
}

Pagination 是通用的分页参数

func (*Pagination) Limit

func (inst *Pagination) Limit() int64

Limit 用于 SQL 查询的页面大小

func (*Pagination) Offset

func (inst *Pagination) Offset() int64

Offset 用于 SQL 查询的条目位置

type PermissionDTO

type PermissionDTO struct {
	ID PermissionID `json:"id"`

	BaseDTO

	Method      string       `json:"method"`
	Path        string       `json:"path"`
	AcceptRoles RoleNameList `json:"accept_roles"`
}

PermissionDTO 表示 Permission 的 REST 网络对象

type PermissionID

type PermissionID int64

PermissionID 是 Permission 的实体 ID

type PermissionQuery

type PermissionQuery struct {
	Pagination Pagination
}

PermissionQuery 查询参数

type PermissionService

type PermissionService interface {
	Insert(c context.Context, o *PermissionDTO) (*PermissionDTO, error)
	Update(c context.Context, id PermissionID, o *PermissionDTO) (*PermissionDTO, error)
	Delete(c context.Context, id PermissionID) error

	Find(c context.Context, id PermissionID) (*PermissionDTO, error)
	List(c context.Context, q *PermissionQuery) ([]*PermissionDTO, error)
}

PermissionService 是针对 PermissionDTO 的服务

type PermissionVO

type PermissionVO struct {
	BaseVO

	Permissions []*PermissionDTO `json:"permissions"`
}

PermissionVO ...

type PhoneNumberDTO added in v1.0.5

type PhoneNumberDTO struct {
	ID PhoneNumberID `json:"id"`

	BaseDTO

	SimpleNunber string `json:"simple_number"`
}

PhoneNumberDTO ...

type PhoneNumberID added in v1.0.5

type PhoneNumberID int64

PhoneNumberID ...

type PhoneNumberQuery added in v1.0.5

type PhoneNumberQuery struct {
	Pagination Pagination
}

PhoneNumberQuery 查询参数

type PhoneNumberService added in v1.0.5

PhoneNumberService ...

type RoleDTO

type RoleDTO struct {
	ID RoleID `json:"id"`

	BaseDTO

	Name RoleName `json:"name"`
}

RoleDTO 表示 Role 的 REST 网络对象

type RoleID

type RoleID int64

RoleID 是 Role 的实体 ID

type RoleName

type RoleName string

RoleName 是 Role 的正式名称

const (
	RoleAdmin  RoleName = "admin"
	RoleAnonym RoleName = "anonym"
	RoleAny    RoleName = "any"
	RoleFriend RoleName = "friend"
	RoleGuest  RoleName = "guest"
	RoleOwner  RoleName = "owner"
	RoleRoot   RoleName = "root"
	RoleUser   RoleName = "user"
)

定义一些常用的角色

func (RoleName) String added in v1.0.20

func (name RoleName) String() string

type RoleNameList

type RoleNameList string

RoleNameList 是一组以逗号分隔的 RoleName

type RoleQuery

type RoleQuery struct {
	Pagination Pagination
}

RoleQuery 查询参数

type RoleService

type RoleService interface {
	Insert(c context.Context, o *RoleDTO) (*RoleDTO, error)
	Update(c context.Context, id RoleID, o *RoleDTO) (*RoleDTO, error)
	Delete(c context.Context, id RoleID) error

	Find(c context.Context, id RoleID) (*RoleDTO, error)
	List(c context.Context, q *RoleQuery) ([]*RoleDTO, error)
}

RoleService 是针对 RoleDTO 的服务

type RoleVO

type RoleVO struct {
	BaseVO

	Roles []*RoleDTO `json:"roles"`
}

RoleVO ...

type SessionDTO

type SessionDTO struct {
	BaseDTO

	ExpiredAt     lang.Time `json:"expired_at"`    // 会话的过期时间
	User          UserDTO   `json:"user"`          // 用户信息
	Authenticated bool      `json:"authenticated"` // 是否已验证

	Properties map[string]string `json:"properties"`
}

SessionDTO 表示会话信息

type SessionVO

type SessionVO struct {
	BaseVO

	Sessions []*SessionDTO `json:"sessions"`
}

SessionVO ...

type TokenDTO added in v1.0.18

type TokenDTO struct {
	BaseDTO

	ExpiredAt lang.Time   `json:"expired_at"` // 令牌的过期时间
	Session   *SessionDTO `json:"session"`    // 会话信息

	Properties map[string]string `json:"properties"`
}

TokenDTO 表示令牌信息

type UserDTO

type UserDTO struct {
	ID UserID `json:"id"`

	BaseDTO

	Name     UserName     `json:"name"`
	NickName string       `json:"nickname"`
	Avatar   string       `json:"avatar"`
	Phone    string       `json:"phone"`
	Email    string       `json:"email"`
	Roles    RoleNameList `json:"roles"`
}

UserDTO 表示 User 的 REST 网络对象

type UserID

type UserID int64

UserID 是通用的用户标识符

func ParseUserID

func ParseUserID(s string) (UserID, error)

ParseUserID 把字符串解析为 UserID

func (UserID) String

func (id UserID) String() string

type UserInfo added in v1.0.17

type UserInfo struct {
	UserDTO
}

UserInfo 包含当前用户的基本信息

func GetUserInfo added in v1.0.17

func GetUserInfo(cc context.Context) (*UserInfo, error)

GetUserInfo 从上下文中获取已绑定的用户信息

type UserInfoBinding added in v1.0.17

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

UserInfoBinding 负责把用户信息绑定到当前上下文

func NewUserInfoBinding added in v1.0.17

func NewUserInfoBinding(info *UserInfo) *UserInfoBinding

NewUserInfoBinding 新建并初始化一个 UserInfoBinding

func (*UserInfoBinding) Key added in v1.0.17

func (inst *UserInfoBinding) Key() string

Key 取绑定键名

func (*UserInfoBinding) UserInfo added in v1.0.17

func (inst *UserInfoBinding) UserInfo() *UserInfo

UserInfo 取用户信息

type UserName

type UserName string

UserName 表示用户名

type UserQuery

type UserQuery struct {
	Pagination Pagination
}

UserQuery 是 User 的查询参数

type UserService

type UserService interface {
	Insert(c context.Context, o *UserDTO) (*UserDTO, error)
	Update(c context.Context, id UserID, o *UserDTO) (*UserDTO, error)
	Delete(c context.Context, id UserID) error

	Find(c context.Context, id UserID) (*UserDTO, error)
	List(c context.Context, q *UserQuery) ([]*UserDTO, error)
}

UserService 是针对 UserDTO 的服务

type UserVO

type UserVO struct {
	BaseVO

	Users []*UserDTO `json:"users"`
}

UserVO ...

type VOGetter

type VOGetter interface {
	GetVO() *BaseVO
}

VOGetter 是获取 BaseVO 的接口

Jump to

Keyboard shortcuts

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