Documentation ¶
Index ¶
- Constants
- type Account
- func (account *Account) AddGroup(ctx context.Context, name string, public bool, description string, user string) (Group, error)
- func (account *Account) AddUser(ctx context.Context, username, name, password string, permission Permission) (User, error)
- func (account *Account) CheckPassword(username, password string) bool
- func (account *Account) DeleteGroup(ctx context.Context, name string) error
- func (account *Account) DeleteGroupUser(ctx context.Context, name, user string) error
- func (account *Account) DeleteUser(ctx context.Context, username string) error
- func (account *Account) GetChannelReceiver(channel string, names []string) map[string]string
- func (account *Account) GetGroup(ctx context.Context, name string) (Group, bool)
- func (account *Account) GetGroups(ctx context.Context, username, nameSearch string, page, pageSize int) ([]Group, error)
- func (account *Account) GetPublicGroups(ctx context.Context, username, nameSearch string, page, pageSize int) ([]Group, error)
- func (account *Account) GetUser(username string) (User, bool)
- func (account *Account) GetUsers(ctx context.Context, nameSearch string, page, pageSize int) ([]User, error)
- func (account *Account) Groups2Users(groups types.Set) types.Set
- func (account *Account) Search(search string) ([]User, []Group)
- func (account *Account) SetGroupReceiver(ctx context.Context, name, ch, receiver string) error
- func (account *Account) SetGroupUser(ctx context.Context, name string, user string, permission GroupPermission) error
- func (account *Account) SetUserPassword(ctx context.Context, username, password string) error
- func (account *Account) SetUserReceiver(ctx context.Context, username, ch, receiver string) error
- func (account *Account) UpdateGroup(ctx context.Context, name string, public bool, description string) error
- func (account *Account) UpdateUser(ctx context.Context, username, name string, permission Permission) error
- type Chan
- type Group
- type GroupPermission
- type GroupUser
- type MapString
- type Permission
- type User
Constants ¶
const ( UPTask = UPTaskRead | UPTaskWrite UPEvent = UPEventRead | UPEventWrite UPDatasource = UPDatasourceRead | UPDatasourceWrite UPGroup = UPGroupRead | UPGroupWrite UPUser = UPUserRead | UPUserWrite DefaultUserPermission = UPTask | UPEvent | UPGroup | UPDatasourceRead | UPUserRead )
权限的合并别名,主要是为了用起来方便
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Account ¶
Account 是账户模块,管理所有的用户和用户组
func (*Account) AddGroup ¶
func (account *Account) AddGroup(ctx context.Context, name string, public bool, description string, user string) (Group, error)
AddGroup 新建一个用户组
func (*Account) AddUser ¶
func (account *Account) AddUser(ctx context.Context, username, name, password string, permission Permission) (User, error)
AddUser 增加一个用户
func (*Account) CheckPassword ¶
CheckPassword 重置用户密码
func (*Account) DeleteGroup ¶
DeleteGroup 删除一个用户组
func (*Account) DeleteGroupUser ¶
DeleteGroupUser 将一个用户从组中移除
func (*Account) DeleteUser ¶
DeleteUser 根据用户名删除一个用户
func (*Account) GetChannelReceiver ¶
GetChannelReceiver 根据 name 参数和 channel 获取接收人列表, name 可以是用户名,也可以是组名 返回值是 map[string]string, 其中 key 是用户名, value 是用户在该消息类型(channel)上的接收账号, 比如邮箱,手机号等 如果 value 为空, 则表示这个人不接收消息通知
func (*Account) GetGroups ¶
func (account *Account) GetGroups(ctx context.Context, username, nameSearch string, page, pageSize int) ([]Group, error)
GetGroups 搜索用户组, 返回 username 所在的用户组
func (*Account) GetPublicGroups ¶
func (account *Account) GetPublicGroups(ctx context.Context, username, nameSearch string, page, pageSize int) ([]Group, error)
GetPublicGroups 搜索公共用户组
func (*Account) GetUsers ¶
func (account *Account) GetUsers(ctx context.Context, nameSearch string, page, pageSize int) ([]User, error)
GetUsers 获取所有用户
func (*Account) Groups2Users ¶
Groups2Users accept a array of group names, and replace the group in array to usernames in this group
func (*Account) SetGroupReceiver ¶
SetGroupReceiver 为组添加一个独立的接收地址,比如群邮箱地址, 聊天群 ID 等
func (*Account) SetGroupUser ¶
func (account *Account) SetGroupUser(ctx context.Context, name string, user string, permission GroupPermission) error
SetGroupUser 向一个组里添加一个成员, 同时带有权限设置
func (*Account) SetUserPassword ¶
SetUserPassword 重置用户密码
func (*Account) SetUserReceiver ¶
SetUserReceiver 为组添加一个独立的接收地址,比如群邮箱地址, 聊天群 ID 等
func (*Account) UpdateGroup ¶
func (account *Account) UpdateGroup(ctx context.Context, name string, public bool, description string) error
UpdateGroup 更新一个用户组
func (*Account) UpdateUser ¶
func (account *Account) UpdateUser(ctx context.Context, username, name string, permission Permission) error
UpdateUser 更新一个用户,包括它的别名,权限和 leader
type Group ¶
type Group struct { *sync.RWMutex `json:"-" db:"-"` Name string `json:"name" db:"name"` Public bool `json:"public" db:"public"` Description string `json:"description" db:"description"` MessageReceivers MapString `json:"message_receivers" db:"message_receivers"` Users []GroupUser `json:"users" db:"-"` CreatedTime time.Time `json:"created_time" db:"created_time"` UpdatedTime time.Time `json:"updated_time" db:"updated_time"` // Permission 代表某用户在改组中的权限, 主要是给 API 使用, 在返回一个用户的组列表时, 需要标识出该用户在各个组中的权限 Permission GroupPermission `json:"permission" db:"permission"` }
Group 代表组信息, Name 是组名,唯一标识; Public 代表改组是不是公开的,如果是则其他人都可以随意加入, 如果不是则对外部人员不可见,需要管理员拉入群聊 Receivers 代表该组的独立接收器,比如专用的 邮箱, 群ID 等. Users 代表实际的组成员
func (*Group) HasPermission ¶
func (group *Group) HasPermission(username string, permission GroupPermission) bool
HasPermission 判断用户 username 是否有某个权限
type GroupPermission ¶
type GroupPermission uint64
GroupPermission 代表组成员权限
const ( GUPAdmin GroupPermission = 1 << iota GUPAlert GUPJoin )
group user permission
func (GroupPermission) MarshalJSON ¶
func (permission GroupPermission) MarshalJSON() ([]byte, error)
MarshalJSON 是对 json.Marshaler 的实现
func (*GroupPermission) Scan ¶
func (permission *GroupPermission) Scan(src interface{}) error
Scan 是对 driver.Scaner 的实现
func (*GroupPermission) UnmarshalJSON ¶
func (permission *GroupPermission) UnmarshalJSON(content []byte) error
UnmarshalJSON 是对 json.Unmarshaler 的实现
type GroupUser ¶
type GroupUser struct { Name string `json:"name" db:"name"` Permission GroupPermission `json:"permission" db:"permission"` CreatedTime time.Time `json:"created_time" db:"created_time"` UpdatedTime time.Time `json:"updated_time" db:"updated_time"` }
GroupUser 代表一个组成员, Name 代表用户名(用户的唯一标识), Permission 代表用户在改组中的权限
type MapString ¶
MapString 主要用来存储消息接收号码, 它实现了 sql/driver 的 Scan 和 Value 方法, 将整个 map 数据 json 序列化后存入 mysql 的一个字段中
type Permission ¶
type Permission uint64
Permission 代表用户权限
const ( UPAdmin Permission = 1 << iota UPTaskWrite UPTaskRead UPEventWrite UPEventRead UPDatasourceWrite UPDatasourceRead UPGroupWrite UPGroupRead UPUserWrite UPUserRead )
user permissions
func (Permission) MarshalJSON ¶
func (permission Permission) MarshalJSON() ([]byte, error)
MarshalJSON 是对 json.Marshaler 的实现
func (*Permission) Scan ¶
func (permission *Permission) Scan(src interface{}) error
Scan 是对 driver.Scaner 的实现
func (*Permission) UnmarshalJSON ¶
func (permission *Permission) UnmarshalJSON(content []byte) error
UnmarshalJSON 是对 json.Unmarshaler 的实现
type User ¶
type User struct { Username string `json:"username" db:"username"` Password string `json:"-" db:"password"` Token string `json:"token" db:"token"` // 用户可以通过 token 来直接调用 http api Name string `json:"name" db:"name"` Avatar string `json:"avatar" db:"avatar"` Permission Permission `json:"permission" db:"permission"` MessageReceivers MapString `json:"message_receivers" db:"message_receivers"` CreatedTime time.Time `json:"created_time" db:"created_time"` UpdatedTime time.Time `json:"updated_time" db:"updated_time"` }
User 代表一个用户, Username 是用户的唯一标识,英文 id
func (User) HasPermission ¶
func (user User) HasPermission(permission Permission) bool
HasPermission 判断一个用户是否拥有某个权限