Documentation
¶
Index ¶
- Constants
- type AuthDTO
- type AuthService
- type AuthVO
- type AvatarDTO
- type AvatarID
- type AvatarQuery
- type AvatarService
- type AvatarVO
- type BaseDTO
- type BaseVO
- type Conditions
- type CurrentUser
- type EmailAddress
- type EmailAddressDTO
- type EmailAddressID
- type EmailAddressQuery
- type EmailAddressService
- type FullPhoneNumber
- type GroupDTO
- type GroupID
- type GroupName
- type GroupQuery
- type GroupService
- type GroupVO
- type ModuleInfo
- type Pagination
- type PermissionCache
- type PermissionChecker
- type PermissionDTO
- type PermissionID
- type PermissionQuery
- type PermissionService
- type PermissionVO
- type PhoneNumber
- type PhoneNumberDTO
- type PhoneNumberID
- type PhoneNumberQuery
- type PhoneNumberService
- type PurePhoneNumber
- type RegionCode2
- type RegionCode3
- type RegionDTO
- type RegionID
- type RegionPhoneCode
- type RegionQuery
- type RegionService
- type RoleDTO
- type RoleID
- type RoleName
- type RoleNameList
- type RoleQuery
- type RoleService
- type RoleVO
- type SessionDTO
- type SessionID
- type SessionIID
- type SessionService
- type SessionUUID
- type SessionVO
- type SimplePhoneNumber
- type SubjectContext
- type SubjectDTO
- type SubjectID
- type SubjectService
- type SubjectVO
- type TokenDTO
- type TokenService
- type TokenVO
- type UserDTO
- type UserID
- type UserInfo
- type UserInfoBinding
- type UserName
- type UserQuery
- type UserService
- type UserVO
- type VOGetter
Constants ¶
const ( ActionLogin = "login" ActionSignUp = "sign-up" ActionResetPassword = "reset-password" ActionChangePassword = "change-password" ActionSendCode = "send-code" )
定义几种常用的授权动作
const ( MechanismPassword = "password" MechanismEmail = "email" MechanismPhone = "sms" MechanismSMS = "sms" )
定义几种常用的验证机制
const ( StepInit = "init" // 初始化 StepPrepare = "prepare" // 准备 StepHelp = "help" // 获取帮助信息 StepSendCode = "sendcode" // 发送验证码 StepApply = "apply" // 应用 StepAuth = "auth" // 验证与授权 )
定义几个常用的验证步骤
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthDTO ¶
type AuthDTO struct { BaseDTO // 采用的验证机制 Mechanism string `json:"mechanism"` // 最终要执行的动作, // 例如: login(登录), sign_up(注册), reset_password(重置密码), 等 Action string `json:"action"` // 表示验证的步骤 Step string `json:"step"` // 将要验证的账号, // 它可能是 UserName | UserID | UserEmail | UserPhone | ... 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, action string, a []*AuthDTO) ([]*AuthDTO, error)
}
AuthService 是针对 AuthDTO 的服务
type AvatarDTO ¶ added in v0.0.7
type AvatarDTO struct { ID AvatarID `json:"id"` BaseDTO Label string `json:"label"` Name string `json:"name"` URL string `json:"url"` }
AvatarDTO 表示一个头像资源
type AvatarQuery ¶ added in v0.0.7
type AvatarQuery struct { Conditions Conditions Pagination Pagination All bool // 查询全部条目 }
AvatarQuery ...
type AvatarService ¶ added in v0.0.7
type AvatarService interface { Find(c context.Context, id AvatarID) (*AvatarDTO, error) List(c context.Context, q *AvatarQuery) ([]*AvatarDTO, error) ListAll(c context.Context) ([]*AvatarDTO, error) }
AvatarService ...
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"` Group GroupID `json:"group"` // 该对象的默认权限分组 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 结构
type Conditions ¶
Conditions 表示查询条件, 取值参考 gorm.DB.Where()
type CurrentUser ¶ added in v0.0.4
type CurrentUser struct { User UserID `json:"user"` Nickname string `json:"nickname"` Language string `json:"language"` // 该用户的本地化语言,取值示例:("zh_cn") Avatar string `json:"avatar"` Roles RoleNameList `json:"roles"` StartedAt lang.Time `json:"started_at"` // 生效时间 ExpiredAt lang.Time `json:"expired_at"` // 过期时间 Properties map[string]string `json:"properties"` }
CurrentUser 表示当前用户
func (*CurrentUser) GetProperty ¶ added in v0.0.8
func (inst *CurrentUser) GetProperty(name string) string
GetProperty ...
func (*CurrentUser) SetPeriod ¶ added in v0.0.8
func (inst *CurrentUser) SetPeriod(from time.Time, maxAge time.Duration)
SetPeriod 以 (t0 + max_age) 的形式设置 StartedAt & ExpiredAt
func (*CurrentUser) SetProperty ¶ added in v0.0.8
func (inst *CurrentUser) SetProperty(name, value string)
SetProperty ...
type EmailAddress ¶
type EmailAddress string
EmailAddress 表示 'user@domain' 形式的邮件地址
func (EmailAddress) String ¶
func (addr EmailAddress) String() string
type EmailAddressDTO ¶
type EmailAddressDTO struct { ID EmailAddressID `json:"id"` BaseDTO Address EmailAddress `json:"address"` }
EmailAddressDTO ...
type EmailAddressQuery ¶
type EmailAddressQuery struct { Conditions Conditions Pagination Pagination All bool // 查询全部条目 }
EmailAddressQuery 查询参数
type EmailAddressService ¶
type EmailAddressService interface { Insert(c context.Context, o *EmailAddressDTO) (*EmailAddressDTO, error) Update(c context.Context, id EmailAddressID, o *EmailAddressDTO) (*EmailAddressDTO, error) Delete(c context.Context, id EmailAddressID) error Find(c context.Context, id EmailAddressID) (*EmailAddressDTO, error) List(c context.Context, q *EmailAddressQuery) ([]*EmailAddressDTO, error) }
EmailAddressService ...
type FullPhoneNumber ¶
type FullPhoneNumber PhoneNumber
FullPhoneNumber 表示完整的电话号码, like: "+86-123-4567-8901"
func ParseFullPhoneNumber ¶
func ParseFullPhoneNumber(str string) (FullPhoneNumber, error)
ParseFullPhoneNumber 把输入的字符串解析为完整的电话号码
func (FullPhoneNumber) Normalize ¶
func (num FullPhoneNumber) Normalize() FullPhoneNumber
Normalize 标准化
func (FullPhoneNumber) Parts ¶
func (num FullPhoneNumber) Parts() (RegionPhoneCode, SimplePhoneNumber, error)
Parts 拆解为:区号 + SimplePhoneNumber
func (FullPhoneNumber) String ¶
func (num FullPhoneNumber) String() string
type GroupDTO ¶ added in v0.0.2
type GroupDTO struct { ID GroupID `json:"id"` BaseDTO Name GroupName `json:"name"` Label string `json:"label"` Description string `json:"description"` Roles RoleNameList `json:"roles"` Enabled bool `json:"enabled"` }
GroupDTO 表示 Group 的 REST 网络对象
type GroupID ¶ added in v0.0.2
type GroupID int64
GroupID 是通用的用户组标识符
func ParseGroupID ¶ added in v0.0.2
ParseGroupID 把字符串解析为 GroupID
type GroupQuery ¶ added in v0.0.2
type GroupQuery struct { Conditions Conditions Pagination Pagination All bool // 查询全部条目 }
GroupQuery 是 Group 的查询参数
type GroupService ¶ added in v0.0.2
type GroupService interface { Insert(c context.Context, o *GroupDTO) (*GroupDTO, error) Update(c context.Context, id GroupID, o *GroupDTO) (*GroupDTO, error) Delete(c context.Context, id GroupID) error Find(c context.Context, id GroupID) (*GroupDTO, error) List(c context.Context, q *GroupQuery) ([]*GroupDTO, error) }
GroupService 是针对 GroupDTO 的服务
type ModuleInfo ¶ added in v0.0.12
func GetModuleInfo ¶ added in v0.0.12
func GetModuleInfo() ModuleInfo
type Pagination ¶
type Pagination struct { Page int64 `json:"page"` // 页码, first=1 Size int `json:"size"` // 页大小 Total int64 `json:"total"` // 所有页面的条目总数 }
Pagination 是通用的分页参数
type PermissionCache ¶
type PermissionCache interface { Clear() Find(c context.Context, want *PermissionDTO) (*PermissionDTO, error) }
PermissionCache 是一个带缓存的 Permission 查询接口
type PermissionChecker ¶ added in v0.0.12
type PermissionChecker interface { GetSubjectContext() *SubjectContext // 添加用户具有的角色 AddRolesHad(roles ...RoleName) PermissionChecker // 添加可接受访问的用户角色 AddRolesAccepted(roles ...RoleName) PermissionChecker // 接受匿名者访问 AcceptAnonymous() PermissionChecker // 检查目标对象的访问权限 CheckObject(o *BaseDTO) error // 完成最终的检查 Check() error }
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 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 ¶
type PhoneNumber string
PhoneNumber 表示电话号码
func (PhoneNumber) String ¶
func (num PhoneNumber) String() string
type PhoneNumberDTO ¶
type PhoneNumberDTO struct { ID PhoneNumberID `json:"id"` BaseDTO RegionCode2 RegionPhoneCode `json:"region"` SimpleNumber SimplePhoneNumber `json:"simple_number"` FullNumber FullPhoneNumber `json:"full_number"` }
PhoneNumberDTO ...
type PhoneNumberQuery ¶
type PhoneNumberQuery struct { Conditions Conditions Pagination Pagination All bool // 查询全部条目 }
PhoneNumberQuery 查询参数
type PhoneNumberService ¶
type PhoneNumberService interface { Insert(c context.Context, o *PhoneNumberDTO) (*PhoneNumberDTO, error) Update(c context.Context, id PhoneNumberID, o *PhoneNumberDTO) (*PhoneNumberDTO, error) Delete(c context.Context, id PhoneNumberID) error Find(c context.Context, id PhoneNumberID) (*PhoneNumberDTO, error) List(c context.Context, q *PhoneNumberQuery) ([]*PhoneNumberDTO, error) }
PhoneNumberService ...
type PurePhoneNumber ¶
type PurePhoneNumber PhoneNumber
PurePhoneNumber 表示完整(且纯粹)的电话号码, like: "8612345678901"
func (PurePhoneNumber) Normalize ¶
func (num PurePhoneNumber) Normalize() PurePhoneNumber
Normalize 标准化
func (PurePhoneNumber) String ¶
func (num PurePhoneNumber) String() string
type RegionCode2 ¶
type RegionCode2 string
RegionCode2 是 ISO 3166-1 标准的二字节地区码 例如:中国(CN), 法国(FR), 俄国(RU), 美国(US), 英国(GB)
func (RegionCode2) String ¶
func (code RegionCode2) String() string
type RegionCode3 ¶
type RegionCode3 string
RegionCode3 是 ISO 3166-1 标准的三字节地区码 例如:中国(CHN), 法国(FRA), 俄国(RUS), 美国(USA), 英国(GBR)
func (RegionCode3) String ¶
func (code RegionCode3) String() string
type RegionDTO ¶
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) FullName string `json:"full_name"` // 完整的名称,例如:中华人民共和国(PRC) Code2 RegionCode2 `json:"code_xx"` // 二字符区域码 Code3 RegionCode3 `json:"code_xxx"` // 三字符区域码 PhoneCode RegionPhoneCode `json:"phone_code"` // 电话区域码 }
RegionDTO 表示国际区号
type RegionPhoneCode ¶
type RegionPhoneCode string
RegionPhoneCode 是数字形式的国际电话区号, 例如:中国(86), 法国(33), 俄国(7), 美国(1), 英国(44)
func (RegionPhoneCode) Normalize ¶
func (code RegionPhoneCode) Normalize() RegionPhoneCode
Normalize 标准化代码
func (RegionPhoneCode) String ¶
func (code RegionPhoneCode) String() string
type RegionQuery ¶
type RegionQuery struct { Conditions Conditions Pagination Pagination All bool // 查询全部条目 }
RegionQuery 查询参数
type RegionService ¶
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 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" // 普通用户 (已登录验证的) )
定义一些常用的角色
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 SessionDTO ¶
type SessionDTO struct { ID SessionID `json:"id"` BaseDTO CurrentUser Authenticated bool `json:"authenticated"` // 是否已验证 }
SessionDTO 表示会话信息
type SessionService ¶ added in v0.0.6
type SessionService interface { Find(c context.Context, id SessionID) (*SessionDTO, error) Insert(c context.Context, se *SessionDTO) (*SessionDTO, error) Update(c context.Context, id SessionID, se *SessionDTO) (*SessionDTO, error) }
SessionService ...
type SessionVO ¶
type SessionVO struct { BaseVO Sessions []*SessionDTO `json:"sessions"` }
SessionVO ...
type SimplePhoneNumber ¶
type SimplePhoneNumber PhoneNumber
SimplePhoneNumber 表示简短的电话号码, 标准化的取值为纯数字形式,不含任何其它字符,like:"12345678901"
func (SimplePhoneNumber) Normalize ¶
func (num SimplePhoneNumber) Normalize() SimplePhoneNumber
Normalize 标准化
func (SimplePhoneNumber) String ¶
func (num SimplePhoneNumber) String() string
type SubjectContext ¶ added in v0.0.12
type SubjectContext struct { Authenticated bool Token *TokenDTO Session *SessionDTO Subject *SubjectDTO Checker PermissionChecker Service SubjectService // 当前用户具有的角色 HaveRoles []RoleName // 当前操作可接受的角色 AcceptedRoles []RoleName }
type SubjectDTO ¶ added in v0.0.3
type SubjectDTO struct { ID SubjectID `json:"id"` Authenticated bool `json:"authenticated"` // 是否已验证 Token TokenDTO `json:"token"` Session SessionDTO `json:"session"` }
SubjectDTO 表示 操作主体 的 REST 网络对象
type SubjectService ¶ added in v0.0.3
type SubjectService interface { GetCurrent(c context.Context) (*SubjectDTO, error) GetCurrentChecker(c context.Context) (PermissionChecker, error) GetCurrentContext(c context.Context) (*SubjectContext, error) }
SubjectService 是针对 SubjectDTO 的服务; 它提供对 Token & Session 的联合查询
type SubjectVO ¶ added in v0.0.3
type SubjectVO struct { BaseVO Subject *SubjectDTO `json:"subject"` }
SubjectVO ...
type TokenDTO ¶
type TokenDTO struct { SessionID SessionID `json:"session_id"` // 会话的 ID SessionUUID SessionUUID `json:"session_uuid"` // 会话的 UUID }
TokenDTO 表示令牌信息
type TokenService ¶ added in v0.0.6
type TokenService interface { GetCurrent(c context.Context) (*TokenDTO, error) PutCurrent(c context.Context, token *TokenDTO) (*TokenDTO, error) }
TokenService ...
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"` Language string `json:"language"` Roles RoleNameList `json:"roles"` Enabled bool `json:"enabled"` }
UserDTO 表示 User 的 REST 网络对象
type UserInfoBinding ¶
type UserInfoBinding struct {
// contains filtered or unexported fields
}
UserInfoBinding 负责把用户信息绑定到当前上下文
func NewUserInfoBinding ¶
func NewUserInfoBinding(info *UserInfo) *UserInfoBinding
NewUserInfoBinding 新建并初始化一个 UserInfoBinding
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 的服务