rbac

package
v1.0.34 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2023 License: MIT Imports: 7 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 Conditions added in v1.0.34

type Conditions struct {
	Query string   `json:"query"`
	Args  []string `json:"args"`
}

Conditions 表示查询条件, 取值参考 gorm.DB.Where()

type EmailAddress added in v1.0.24

type EmailAddress string

EmailAddress 表示 'user@domain' 形式的邮件地址

func (EmailAddress) String added in v1.0.24

func (addr EmailAddress) String() string

type EmailAddressDTO added in v1.0.5

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

	BaseDTO

	Address EmailAddress `json:"address"`
}

EmailAddressDTO ...

type EmailAddressID added in v1.0.5

type EmailAddressID int64

EmailAddressID ...

type EmailAddressQuery added in v1.0.5

type EmailAddressQuery struct {
	Conditions Conditions
	Pagination Pagination
	All        bool // 查询全部条目
}

EmailAddressQuery 查询参数

type EmailAddressService added in v1.0.5

EmailAddressService ...

type FullPhoneNumber added in v1.0.24

type FullPhoneNumber PhoneNumber

FullPhoneNumber 表示完整的电话号码

func (FullPhoneNumber) String added in v1.0.24

func (num FullPhoneNumber) String() string

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 PermissionCache added in v1.0.29

type PermissionCache interface {
	Clear()
	Find(c context.Context, want *PermissionDTO) (*PermissionDTO, error)
}

PermissionCache 是一个带缓存的 Permission 查询接口

type PermissionDTO

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

	BaseDTO

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

PermissionDTO 表示 Permission 的 REST 网络对象

type PermissionID

type PermissionID int64

PermissionID 是 Permission 的实体 ID

type PermissionQuery

type PermissionQuery struct {
	Conditions Conditions
	Pagination Pagination
	All        bool // 查询全部条目
}

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)
	ListAll(c context.Context) ([]*PermissionDTO, error)

	GetCache() PermissionCache
}

PermissionService 是针对 PermissionDTO 的服务

type PermissionVO

type PermissionVO struct {
	BaseVO

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

PermissionVO ...

type PhoneNumber added in v1.0.24

type PhoneNumber string

PhoneNumber 表示电话号码

func (PhoneNumber) String added in v1.0.24

func (num PhoneNumber) String() string

type PhoneNumberDTO added in v1.0.5

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

	BaseDTO

	RegionCode2  RegionPhoneCode   `json:"region"`
	SimpleNumber SimplePhoneNumber `json:"simple_number"`
	FullNumber   FullPhoneNumber   `json:"full_number"`
}

PhoneNumberDTO ...

type PhoneNumberID added in v1.0.5

type PhoneNumberID int64

PhoneNumberID ...

type PhoneNumberQuery added in v1.0.5

type PhoneNumberQuery struct {
	Conditions Conditions
	Pagination Pagination
	All        bool // 查询全部条目
}

PhoneNumberQuery 查询参数

type PhoneNumberService added in v1.0.5

PhoneNumberService ...

type RegionCode2 added in v1.0.24

type RegionCode2 string

RegionCode2 是 ISO 3166-1 标准的二字节地区码 例如:中国(CN), 法国(FR), 俄国(RU), 美国(US), 英国(GB)

func (RegionCode2) String added in v1.0.24

func (code RegionCode2) String() string

type RegionCode3 added in v1.0.24

type RegionCode3 string

RegionCode3 是 ISO 3166-1 标准的三字节地区码 例如:中国(CHN), 法国(FRA), 俄国(RUS), 美国(USA), 英国(GBR)

func (RegionCode3) String added in v1.0.24

func (code RegionCode3) String() string

type RegionDTO added in v1.0.24

type RegionDTO struct {
	ID RegionID `json:"id"`

	BaseDTO

	FlagURL     string          `json:"flag_url"`    // 国旗(或区旗)图标的URL
	DisplayName string          `json:"label"`       // 显示名称,通常是本地化的名称
	SimpleName  string          `json:"simple_name"` // 区域简称,例如:chn(中国), fra(France), usa(United States)
	Code2       RegionCode2     `json:"code_xx"`     // 二字符区域码
	Code3       RegionCode3     `json:"code_xxx"`    // 三字符区域码
	PhoneCode   RegionPhoneCode `json:"phone_code"`  // 电话区域码
}

RegionDTO 表示国际区号

type RegionID added in v1.0.24

type RegionID int

RegionID ...

type RegionPhoneCode added in v1.0.24

type RegionPhoneCode string

RegionPhoneCode 是数字形式的国际电话区号, 例如:中国(+86), 法国(+33), 俄国(+7), 美国(+1), 英国(+44)

func (RegionPhoneCode) String added in v1.0.24

func (code RegionPhoneCode) String() string

type RegionQuery added in v1.0.24

type RegionQuery struct {
	Conditions Conditions
	Pagination Pagination
	All        bool // 查询全部条目
}

RegionQuery 查询参数

type RegionService added in v1.0.24

type RegionService interface {
	Insert(c context.Context, o *RegionDTO) (*RegionDTO, error)
	Update(c context.Context, id RegionID, o *RegionDTO) (*RegionDTO, error)
	Delete(c context.Context, id RegionID) error

	Find(c context.Context, id RegionID) (*RegionDTO, error)
	List(c context.Context, q *RegionQuery) ([]*RegionDTO, error)
}

RegionService ...

type RoleDTO

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

	BaseDTO

	Name        RoleName `json:"name"`
	Description string   `json:"description"`
}

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

func NewRoleNameList added in v1.0.27

func NewRoleNameList(names ...RoleName) RoleNameList

NewRoleNameList 新建角色列表

func (RoleNameList) List added in v1.0.27

func (list RoleNameList) List() []RoleName

List 拆分成单项列表

func (RoleNameList) Normalize added in v1.0.27

func (list RoleNameList) Normalize() RoleNameList

Normalize 标准化

type RoleQuery

type RoleQuery struct {
	Conditions Conditions
	Pagination Pagination
	All        bool // 查询全部条目
}

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 SimplePhoneNumber added in v1.0.24

type SimplePhoneNumber PhoneNumber

SimplePhoneNumber 表示简短的电话号码

func (SimplePhoneNumber) String added in v1.0.24

func (num SimplePhoneNumber) String() string

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"`
	Enabled  bool         `json:"enabled"`
}

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 表示用户名

func (UserName) String added in v1.0.24

func (name UserName) String() string

type UserQuery

type UserQuery struct {
	Conditions Conditions
	Pagination Pagination
	All        bool // 查询全部条目
}

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