54 lines
996 B
Go
54 lines
996 B
Go
package contracts
|
|
|
|
type UserRuntime struct {
|
|
platform string
|
|
saas string
|
|
}
|
|
|
|
// 账号运行平台
|
|
func (this UserRuntime) Platform() string {
|
|
return this.platform
|
|
}
|
|
|
|
// 账号运行租户
|
|
func (this UserRuntime) SaaS() string {
|
|
return this.saas
|
|
}
|
|
|
|
type User interface {
|
|
Runtime() UserRuntime
|
|
// 用户ID
|
|
ID() int64
|
|
// 用户UUID
|
|
Uuid() string
|
|
// 用户名称
|
|
Username() string
|
|
// 用户昵称
|
|
Nickname() string
|
|
// 用户明细
|
|
GetUserInfo() map[string]any
|
|
// 用户权限
|
|
Roles() []string
|
|
// 用户权限检查
|
|
HasUserRoles(roles ...string) bool
|
|
// 是否匿名用户
|
|
IsAnonymous() bool
|
|
}
|
|
|
|
// 用户
|
|
type GetUser func(uuid string, options ...UserRuntimeOption) (User, error)
|
|
|
|
type UserRuntimeOption func(option *UserRuntime)
|
|
|
|
func UserRuntimePlatform(value string) UserRuntimeOption {
|
|
return func(option *UserRuntime) {
|
|
option.platform = value
|
|
}
|
|
}
|
|
|
|
func UserRuntimeSaaS(value string) UserRuntimeOption {
|
|
return func(option *UserRuntime) {
|
|
option.saas = value
|
|
}
|
|
}
|