contracts/user.go

54 lines
996 B
Go
Raw Normal View History

2023-04-12 16:56:55 +08:00
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
}
2023-04-12 16:56:55 +08:00
type User interface {
Runtime() UserRuntime
2023-04-12 16:56:55 +08:00
// 用户ID
2023-12-05 16:01:42 +08:00
ID() int64
2023-04-12 16:56:55 +08:00
// 用户UUID
Uuid() string
// 用户名称
Username() string
// 用户昵称
Nickname() string
// 用户明细
GetUserInfo() map[string]any
2023-04-12 16:56:55 +08:00
// 用户权限
Roles() []string
// 用户权限检查
HasUserRoles(roles ...string) bool
// 是否匿名用户
IsAnonymous() bool
2023-04-12 16:56:55 +08:00
}
// 用户
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
}
}