rbac

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2023 License: MIT Imports: 6 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertTimeFromGorm

func ConvertTimeFromGorm(t gorm.DeletedAt) lang.Time

ConvertTimeFromGorm ...

func ConvertTimeToGorm

func ConvertTimeToGorm(t lang.Time) gorm.DeletedAt

ConvertTimeToGorm ...

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

	Mechanism string      `json:"mechanism"`
	Account   string      `json:"account"`
	Secret    lang.Base64 `json:"secret"`
}

AuthDTO 用于登录认证

type AuthService

type AuthService interface {
	Login(c context.Context, a *AuthDTO) (*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 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 结构

func (*BaseVO) GetVO

func (inst *BaseVO) GetVO() *BaseVO

GetVO 实现 BaseGetter

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 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 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 的数据库实体

func (PermissionEntity) TableName

func (PermissionEntity) TableName() string

TableName ...

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 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 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 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 RoleDTO

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

	BaseDTO

	Name RoleName `json:"name"`
}

RoleDTO 表示 Role 的 REST 网络对象

type RoleEntity

type RoleEntity struct {
	ID RoleID

	BaseEntity

	Name RoleName `gorm:"unique"`
}

RoleEntity 表示 Role 的数据库实体

func (RoleEntity) TableName

func (RoleEntity) TableName() string

TableName ...

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"
)

定义一些常用的角色

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"`       // 用户信息
	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 GetTableGroup

func GetTableGroup() *TableGroup

GetTableGroup ...

func (*TableGroup) Entities

func (inst *TableGroup) Entities() []any

Entities ...

func (*TableGroup) Name

func (inst *TableGroup) Name() string

Name ...

func (*TableGroup) Namespace

func (inst *TableGroup) Namespace() string

Namespace ...

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 的数据库实体

func (UserEntity) TableName

func (UserEntity) TableName() string

TableName ...

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 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