Documentation
¶
Overview ¶
Package group 提供群组实体:成员角色、邀请/申请审核、公告、最大人数、封禁名单。
把 examples/clan 里用 relationship+tournament+wallet 现场组合的"公会"语义, 沉淀成有边界的一等包——clan 是 demo,group 是可复用的实体封装。
与 pkg/domain/relationship 的分工:
- relationship 是图原语(二部有向图 + 状态编码),无群组语义;
- group 是群组语义封装:owner/admin/member 角色、邀请/申请审核流、 公告、最大人数、banlist,内部用 relationship.Graph 存成员边 (source=groupID, destination=userID, State=角色)。
角色编码复用 relationship 的常量:StateOwner / StateAdmin / StateActive(member) / StatePending(申请中)。group 在其上加业务规则(如 owner 唯一、admin 可踢人、 banlist 用户不能加入)。
设计要点:Group 为一等实体,成员状态可流转。 零值不可用,用 New 构造。Store 并发安全。
Index ¶
- Constants
- Variables
- type Group
- type Option
- type Store
- func (s *Store) Approve(groupID, approver, userID string) error
- func (s *Store) Ban(groupID, actor, userID string) error
- func (s *Store) Banned(groupID string) ([]string, error)
- func (s *Store) Create(g Group) error
- func (s *Store) Demote(groupID, owner, userID string) error
- func (s *Store) Info(groupID string) (Group, error)
- func (s *Store) Join(groupID, userID string) error
- func (s *Store) Kick(groupID, actor, userID string) error
- func (s *Store) Leave(groupID, userID string) error
- func (s *Store) MemberCount(groupID string) (int, error)
- func (s *Store) Members(groupID string) (owners, admins, members []string, err error)
- func (s *Store) Pending(groupID string) ([]string, error)
- func (s *Store) Promote(groupID, owner, userID string) error
- func (s *Store) Reject(groupID, approver, userID string) error
- func (s *Store) Request(groupID, userID string) error
- func (s *Store) Role(groupID, userID string) (role int, joinedAt int64, err error)
- func (s *Store) SetAnnouncement(groupID, actor, text string) error
- func (s *Store) SetMaxMembers(groupID, owner string, max int) error
- func (s *Store) TransferOwner(groupID, owner, newOwner string) error
- func (s *Store) Unban(groupID, actor, userID string) error
Constants ¶
const ( RoleMember = relationship.StateActive // 普通成员 RoleAdmin = relationship.StateAdmin // 管理员 RoleOwner = relationship.StateOwner // 拥有者(唯一) RolePending = relationship.StatePending // 申请中(待审核) )
角色常量(复用 relationship 的状态编码,语义别名)。
Variables ¶
var ( ErrExists = errors.New("group: already exists") ErrNotFound = errors.New("group: not found") ErrAlreadyMember = errors.New("group: already a member") ErrNotMember = errors.New("group: not a member") ErrNotPending = errors.New("group: not a pending request") ErrFull = errors.New("group: max members reached") ErrBanned = errors.New("group: user is banned") ErrNotBanned = errors.New("group: user is not banned") ErrOwnerCannotLeave = errors.New("group: owner cannot leave, transfer first") ErrNoPermission = errors.New("group: no permission") ErrCannotKickPeer = errors.New("group: cannot kick a peer of equal or higher role") )
错误定义。
Functions ¶
This section is empty.
Types ¶
type Group ¶
type Group struct {
ID string
Name string
OwnerID string
Announcement string
MaxMembers int
CreatedAt int64
}
Group 一个群组实体。
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store 管理群组集合及其成员关系。
func (*Store) Ban ¶
Ban 封禁用户(加入 banlist,立即移除成员关系)。仅 owner/admin 可操作。 不能封禁同级或更高(admin 不能 ban owner/admin)。
func (*Store) MemberCount ¶
MemberCount 返回正式成员数(含 owner/admin/member,不含 pending)。
func (*Store) Request ¶
Request 用户申请加入(进入待审核)。banned/已成员/满员则失败。 返回后由 admin/owner 用 Approve(groupID, userID) 审批。
func (*Store) SetAnnouncement ¶
SetAnnouncement 设置群公告。仅 owner/admin 可操作。
func (*Store) SetMaxMembers ¶
SetMaxMembers 设置最大人数。仅 owner 可操作。
func (*Store) TransferOwner ¶
TransferOwner 转让群主。仅 owner 可操作,新 owner 必须是 member/admin。