Documentation
¶
Index ¶
- Constants
- func ConvertTimeFromGorm(t gorm.DeletedAt) lang.Time
- func ConvertTimeToGorm(t lang.Time) gorm.DeletedAt
- func CopyBaseFieldsFromDtoToEntity(src *BaseDTO, dst *BaseEntity)
- func CopyBaseFieldsFromEntityToDTO(src *BaseEntity, dst *BaseDTO)
- type AuthDTO
- type AuthService
- type AuthVO
- type BaseDTO
- type BaseEntity
- type BaseVO
- type EmailAddressConvertor
- type EmailAddressDAO
- type EmailAddressDTO
- type EmailAddressEntity
- type EmailAddressID
- type EmailAddressQuery
- type EmailAddressService
- type Pagination
- type PermissionConvertor
- type PermissionDAO
- type PermissionDTO
- type PermissionEntity
- type PermissionID
- type PermissionQuery
- type PermissionService
- type PermissionVO
- type PhoneNumberConvertor
- type PhoneNumberDAO
- type PhoneNumberDTO
- type PhoneNumberEntity
- type PhoneNumberID
- type PhoneNumberQuery
- type PhoneNumberService
- type RoleConvertor
- type RoleDAO
- type RoleDTO
- type RoleEntity
- type RoleID
- type RoleName
- type RoleNameList
- type RoleQuery
- type RoleService
- type RoleVO
- type SessionDTO
- type SessionService
- type SessionVO
- type TableGroup
- type UserConvertor
- type UserDAO
- type UserDTO
- type UserEntity
- type UserID
- type UserName
- type UserQuery
- type UserService
- type UserVO
- type VOGetter
Constants ¶
const ( ActionLogin = "login" ActionSignUp = "sign-up" ActionResetPassword = "reset-password" ActionChangePassword = "change-password" )
定义几种常用的授权动作
const ( MechanismPassword = "password" MechanismEmail = "email" MechanismPhone = "phone" )
定义几种常用的验证机制
Variables ¶
This section is empty.
Functions ¶
func ConvertTimeFromGorm ¶
ConvertTimeFromGorm ...
func CopyBaseFieldsFromDtoToEntity ¶
func CopyBaseFieldsFromDtoToEntity(src *BaseDTO, dst *BaseEntity)
CopyBaseFieldsFromDtoToEntity ...
func CopyBaseFieldsFromEntityToDTO ¶
func CopyBaseFieldsFromEntityToDTO(src *BaseEntity, dst *BaseDTO)
CopyBaseFieldsFromEntityToDTO ...
Types ¶
type AuthDTO ¶
type AuthDTO struct { BaseDTO Action string `json:"action"` Mechanism string `json:"mechanism"` Account string `json:"account"` Secret lang.Base64 `json:"secret"` User *UserDTO `json:"user"` // 用户信息 (optional) Step int `json:"step"` // 表示验证的步骤 NewPassword lang.Base64 `json:"new_password"` // 新的密码(用于注册,设置,重设密码) Success bool `json:"success"` // 是否完成并且成功 Properties map[string]string `json:"properties"` // 其它扩展属性 }
AuthDTO 用于登录认证
type AuthService ¶
AuthService 是针对 AuthDTO 的服务
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 BaseEntity ¶
type BaseEntity struct { UUID lang.UUID `gorm:"unique"` CreatedAt time.Time UpdatedAt time.Time DeletedAt gorm.DeletedAt `gorm:"index"` Owner UserID Creator UserID Updater UserID }
BaseEntity 是基本的数据库实体
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 EmailAddressConvertor ¶ added in v1.0.5
type EmailAddressConvertor interface { ConvertE2D(c context.Context, entity *EmailAddressEntity) (*EmailAddressDTO, error) ConvertD2E(c context.Context, dto *EmailAddressDTO) (*EmailAddressEntity, error) ConvertListE2D(c context.Context, entity []*EmailAddressEntity) ([]*EmailAddressDTO, error) }
EmailAddressConvertor ...
type EmailAddressDAO ¶ added in v1.0.5
type EmailAddressDAO interface { Insert(db *gorm.DB, o *EmailAddressEntity) (*EmailAddressEntity, error) Update(db *gorm.DB, id EmailAddressID, updater func(*EmailAddressEntity)) (*EmailAddressEntity, error) Delete(db *gorm.DB, id EmailAddressID) error Find(db *gorm.DB, id EmailAddressID) (*EmailAddressEntity, error) List(db *gorm.DB, q *EmailAddressQuery) ([]*EmailAddressEntity, error) }
EmailAddressDAO ...
type EmailAddressDTO ¶ added in v1.0.5
type EmailAddressDTO struct { ID EmailAddressID `json:"id"` BaseDTO Address string `json:"address"` }
EmailAddressDTO ...
type EmailAddressEntity ¶ added in v1.0.5
type EmailAddressEntity struct { ID EmailAddressID BaseEntity Address string `gorm:"unique"` }
EmailAddressEntity ...
func (EmailAddressEntity) TableName ¶ added in v1.0.5
func (EmailAddressEntity) TableName() string
TableName ...
type EmailAddressQuery ¶ added in v1.0.5
type EmailAddressQuery struct {
Pagination Pagination
}
EmailAddressQuery 查询参数
type EmailAddressService ¶ added in v1.0.5
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 Pagination ¶
type Pagination struct { Page int64 `json:"page"` // 页码, first=1 Size int `json:"size"` // 页大小 Total int64 `json:"total"` // 所有页面的条目总数 }
Pagination 是通用的分页参数
type PermissionConvertor ¶
type PermissionConvertor interface { ConvertE2D(c context.Context, entity *PermissionEntity) (*PermissionDTO, error) ConvertD2E(c context.Context, dto *PermissionDTO) (*PermissionEntity, error) ConvertListE2D(c context.Context, entity []*PermissionEntity) ([]*PermissionDTO, error) }
PermissionConvertor 负责 dto <==> entity 的转换
type PermissionDAO ¶
type PermissionDAO interface { Insert(db *gorm.DB, o *PermissionEntity) (*PermissionEntity, error) Update(db *gorm.DB, id PermissionID, updater func(*PermissionEntity)) (*PermissionEntity, error) Delete(db *gorm.DB, id PermissionID) error Find(db *gorm.DB, id PermissionID) (*PermissionEntity, error) List(db *gorm.DB, q *PermissionQuery) ([]*PermissionEntity, error) }
PermissionDAO 是数据库访问对象
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 PermissionEntity ¶
type PermissionEntity struct { ID PermissionID BaseEntity Method string Path string Resource string `gorm:"unique"` // like 'method + ":" + path' AcceptRoles RoleNameList }
PermissionEntity 表示 Permission 的数据库实体
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 PhoneNumberConvertor ¶ added in v1.0.5
type PhoneNumberConvertor interface { ConvertE2D(c context.Context, entity *PhoneNumberEntity) (*PhoneNumberDTO, error) ConvertD2E(c context.Context, dto *PhoneNumberDTO) (*PhoneNumberEntity, error) ConvertListE2D(c context.Context, entity []*PhoneNumberEntity) ([]*PhoneNumberDTO, error) }
PhoneNumberConvertor ...
type PhoneNumberDAO ¶ added in v1.0.5
type PhoneNumberDAO interface { Insert(db *gorm.DB, o *PhoneNumberEntity) (*PhoneNumberEntity, error) Update(db *gorm.DB, id PhoneNumberID, updater func(*PhoneNumberEntity)) (*PhoneNumberEntity, error) Delete(db *gorm.DB, id PhoneNumberID) error Find(db *gorm.DB, id PhoneNumberID) (*PhoneNumberEntity, error) List(db *gorm.DB, q *PhoneNumberQuery) ([]*PhoneNumberEntity, error) }
PhoneNumberDAO ...
type PhoneNumberDTO ¶ added in v1.0.5
type PhoneNumberDTO struct { ID PhoneNumberID `json:"id"` BaseDTO SimpleNunber string `json:"simple_number"` }
PhoneNumberDTO ...
type PhoneNumberEntity ¶ added in v1.0.5
type PhoneNumberEntity struct { ID PhoneNumberID BaseDTO SimpleNunber string `gorm:"unique"` }
PhoneNumberEntity ...
func (PhoneNumberEntity) TableName ¶ added in v1.0.5
func (PhoneNumberEntity) TableName() string
TableName ...
type PhoneNumberQuery ¶ added in v1.0.5
type PhoneNumberQuery struct {
Pagination Pagination
}
PhoneNumberQuery 查询参数
type PhoneNumberService ¶ added in v1.0.5
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 RoleConvertor ¶
type RoleConvertor interface { ConvertE2D(c context.Context, entity *RoleEntity) (*RoleDTO, error) ConvertD2E(c context.Context, dto *RoleDTO) (*RoleEntity, error) ConvertListE2D(c context.Context, entity []*RoleEntity) ([]*RoleDTO, error) }
RoleConvertor 负责 dto <==> entity 的转换
type RoleDAO ¶
type RoleDAO interface { Insert(db *gorm.DB, o *RoleEntity) (*RoleEntity, error) Update(db *gorm.DB, id RoleID, updater func(*RoleEntity)) (*RoleEntity, error) Delete(db *gorm.DB, id RoleID) error Find(db *gorm.DB, id RoleID) (*RoleEntity, error) List(db *gorm.DB, q *RoleQuery) ([]*RoleEntity, error) }
RoleDAO 是数据库访问对象
type RoleEntity ¶
type RoleEntity struct { ID RoleID BaseEntity Name RoleName `gorm:"unique"` }
RoleEntity 表示 Role 的数据库实体
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 { BaseDTO ExpiredAt lang.Time `json:"expired_at"` // 会话的过期时间 User UserDTO `json:"user"` // 用户信息 Authorized bool `json:"authorized"` // 是否已授权 Properties map[string]string `json:"properties"` }
SessionDTO 表示会话信息
type SessionService ¶
type SessionService interface {
GetCurrent(c context.Context) (*SessionDTO, error)
}
SessionService 是针对 SessionDTO 的服务
type SessionVO ¶
type SessionVO struct { BaseVO Sessions []*SessionDTO `json:"sessions"` }
SessionVO ...
type TableGroup ¶
type TableGroup struct { }
TableGroup ...
func (*TableGroup) SetNamer ¶
func (inst *TableGroup) SetNamer(namer libgorm.TableNamer)
SetNamer ...
type UserConvertor ¶
type UserConvertor interface { ConvertE2D(c context.Context, entity *UserEntity) (*UserDTO, error) ConvertD2E(c context.Context, dto *UserDTO) (*UserEntity, error) ConvertListE2D(c context.Context, entity []*UserEntity) ([]*UserDTO, error) }
UserConvertor 负责 dto <==> entity 的转换
type UserDAO ¶
type UserDAO interface { Insert(db *gorm.DB, o *UserEntity) (*UserEntity, error) Update(db *gorm.DB, id UserID, updater func(o *UserEntity)) (*UserEntity, error) Delete(db *gorm.DB, id UserID) error FindByAny(db *gorm.DB, text string) (*UserEntity, error) FindByName(db *gorm.DB, name string) (*UserEntity, error) FindByPhone(db *gorm.DB, phone string) (*UserEntity, error) FindByEmail(db *gorm.DB, email string) (*UserEntity, error) Find(db *gorm.DB, id UserID) (*UserEntity, error) List(db *gorm.DB, q *UserQuery) ([]*UserEntity, error) }
UserDAO 是数据库访问对象
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 UserEntity ¶
type UserEntity struct { ID UserID BaseEntity Name UserName `gorm:"unique"` // 用户名 Nickname string // 昵称 Avatar string // 头像 (HTTP-URL) Phone string // 主要的手机号 Email string // 主要的 e-mail 地址 Roles RoleNameList // 用户的角色 Password lang.Hex // 用户当前的密码 Salt lang.Hex // 跟密码相关的盐 }
UserEntity 表示 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 的服务