Documentation
¶
Overview ¶
Package groups owns group admission, management and voluntary entertainment.
Index ¶
- Constants
- Variables
- func NewErrorDetail(base error, reason, field string, retryAfter int64) error
- func OpenAPI() []byte
- func TraceParentFromContext(ctx context.Context) string
- func WithTraceParent(ctx context.Context, tp string) context.Context
- type Action
- type ActionQuery
- type Actor
- type Analyzer
- type AuditEntry
- type Authorizer
- type Blacklist
- type BlacklistInput
- type Bot
- type BotIdentity
- type BotScope
- type Bulk
- type BulkItem
- type BulkResult
- type BulkSkippedItem
- type CardField
- type Command
- type Delivery
- type DirectoryGroup
- type DirectoryQuery
- type DirectoryRecord
- type EligibilityChange
- type ErrorDetail
- type Event
- type Facts
- type FactsProvider
- type GroupConfig
- type GroupConfigInput
- type GroupCounts
- type GroupSettings
- type GroupSummary
- type Hit
- type HitQuery
- type IdentityResolver
- type ListQuery
- type ManagedGroup
- type Member
- type MemberQuery
- type Message
- type MessageQuery
- type MyGroup
- type OutboxReader
- type Outcome
- type OwnerGroupRecord
- type Page
- type ReadTx
- type Report
- type ReportQuery
- type Repository
- type Result
- type Row
- type Service
- func (s *Service) Actions(ctx context.Context, p account.Principal, g, cursor string, limit int) (Page[Action], error)
- func (s *Service) Audits(ctx context.Context, p account.Principal, g, cursor string, limit int) (Page[AuditEntry], error)
- func (s *Service) Batch(ctx context.Context, p account.Principal, g, key string, in Bulk) (BulkResult, error)
- func (s *Service) Blacklist(ctx context.Context, p account.Principal, g, cursor string, limit int) (Page[Blacklist], error)
- func (s *Service) Blacklists(ctx context.Context, p account.Principal, key string, in BlacklistInput) (Result, error)
- func (s *Service) Cleanup(ctx context.Context, g, cursor string) (string, error)
- func (s *Service) CleanupFrequency(ctx context.Context, g, cursor string) (string, error)
- func (s *Service) CleanupIdempotency(ctx context.Context, bucketName, cursor string, maxAge time.Duration) (string, error)
- func (s *Service) CleanupOutbox(ctx context.Context, maxAge time.Duration) (int, error)
- func (s *Service) Command(ctx context.Context, p account.Principal, g, key string, cmd Command) (Result, error)
- func (s *Service) Configuration(ctx context.Context, p account.Principal, g string) (GroupConfig, error)
- func (s *Service) Configure(ctx context.Context, p account.Principal, key string, in GroupConfigInput) (GroupConfig, error)
- func (s *Service) Consume(ctx context.Context, event UpstreamEvent) error
- func (s *Service) Deliveries(ctx context.Context, p account.Principal, g, cursor string, limit int) (Page[Delivery], error)
- func (s *Service) Directory(ctx context.Context, p account.Principal, q DirectoryQuery) (Page[DirectoryGroup], error)
- func (s *Service) Execute(ctx context.Context, g, id string) (Action, error)
- func (s *Service) Fanout(ctx context.Context, e Event) error
- func (s *Service) Groups(ctx context.Context, p account.Principal, cursor string, limit int) (Page[GroupSummary], error)
- func (s *Service) GroupsForOwner(ctx context.Context, owner account.Principal, cursor string, limit int) (Page[ManagedGroup], error)
- func (s *Service) Hits(ctx context.Context, p account.Principal, g, cursor string, limit int) (Page[Hit], error)
- func (s *Service) Ingest(ctx context.Context, g string, event Event, m Message) error
- func (s *Service) MemberEvent(ctx context.Context, g string, event Event, owner string) error
- func (s *Service) Members(ctx context.Context, p account.Principal, g, cursor string, limit int) (Page[Member], error)
- func (s *Service) Messages(ctx context.Context, p account.Principal, g, cursor string, limit int) (Page[Message], error)
- func (s *Service) MyGroups(ctx context.Context, p account.Principal, cursor string, limit int) (Page[MyGroup], error)
- func (s *Service) Progress(ctx context.Context, p account.Principal, g string) (Member, error)
- func (s *Service) QueryActions(ctx context.Context, p account.Principal, g string, q ActionQuery) (Page[Action], error)
- func (s *Service) QueryHits(ctx context.Context, p account.Principal, g string, q HitQuery) (Page[Hit], error)
- func (s *Service) QueryMembers(ctx context.Context, p account.Principal, g string, q MemberQuery) (Page[Member], error)
- func (s *Service) QueryMessages(ctx context.Context, p account.Principal, g string, q MessageQuery) (Page[Message], error)
- func (s *Service) QueryReports(ctx context.Context, p account.Principal, g string, q ReportQuery) (Page[Report], error)
- func (s *Service) Recover(ctx context.Context, g, cursor string) (string, error)
- func (s *Service) Reports(ctx context.Context, p account.Principal, g, cursor string, limit int) (Page[Report], error)
- func (s *Service) Subscriptions(ctx context.Context, p account.Principal, g, cursor string, limit int) (Page[Subscription], error)
- func (s *Service) Sweep(ctx context.Context, g, cursor string) (string, error)
- func (s *Service) Warnings(ctx context.Context, p account.Principal, g, cursor string, limit int) (Page[Warnings], error)
- func (s *Service) Watch(ctx context.Context, p account.Principal, g, cursor string, limit int) (Page[Watch], error)
- type Subscription
- type Tx
- type UpstreamEvent
- type Warnings
- type Watch
Constants ¶
const MaxEventGroups = 1000
A bounded transaction provides all-or-nothing fanout. Overflow is a failure, not a partial acknowledgement; Sweep remains available for periodic recovery.
const OutboxChannel = "groups_outbox"
Variables ¶
var ( ErrUnprocessable = errors.New("groups_unprocessable") ErrInvalid = errors.New("groups_invalid_request") ErrUnauthenticated = errors.New("groups_unauthenticated") ErrForbidden = errors.New("groups_forbidden") ErrNotFound = errors.New("groups_not_found") ErrConflict = errors.New("groups_conflict") ErrDisabled = errors.New("groups_disabled") ErrCooldown = errors.New("groups_cooldown") )
Functions ¶
func NewErrorDetail ¶ added in v0.1.1
func OpenAPI ¶
func OpenAPI() []byte
OpenAPI returns the exact provider contract for consumer compatibility checks.
func TraceParentFromContext ¶ added in v0.1.1
TraceParentFromContext returns the active traceparent attached to ctx, if any.
Types ¶
type Action ¶
type Action struct {
LeaseUntil *time.Time `json:"lease_until,omitempty"`
ID string `json:"id"`
Group string `json:"group"`
Actor Actor `json:"actor"`
Capability string `json:"capability"`
Command Command `json:"command"`
State string `json:"state"`
Result string `json:"result"`
Created time.Time `json:"created"`
}
type ActionQuery ¶ added in v0.1.1
type AuditEntry ¶ added in v0.1.1
type Authorizer ¶
type BlacklistInput ¶
type BotIdentity ¶
type BotScope ¶
BotScope identifies a registered adapter instance. Platform is onebot or official; connect is never a bot transport or evidence of a shared QQ identity.
type BulkResult ¶
type BulkResult struct {
Items []BulkItem `json:"items"`
Executed []BulkItem `json:"executed"`
Skipped []BulkSkippedItem `json:"skipped"`
}
type BulkSkippedItem ¶ added in v0.1.1
type CardField ¶
CardField separates disclosure permission from source availability. Only allowed and available fields may enter a group card; absence is not a violation.
type DirectoryGroup ¶ added in v0.1.1
type DirectoryGroup struct {
ID string `json:"id"`
School string `json:"school"`
Name string `json:"name"`
Number string `json:"number"`
Category string `json:"category"`
Description string `json:"description"`
Mode string `json:"mode"`
RequireStudent bool `json:"require_student"`
AcceptAlumni bool `json:"accept_alumni"`
AcceptTemporary bool `json:"accept_temporary"`
RequiresPassword bool `json:"requires_password"`
PasswordHint string `json:"password_hint,omitempty"`
Joined bool `json:"joined"`
State string `json:"state"`
}
type DirectoryQuery ¶ added in v0.1.1
type DirectoryRecord ¶ added in v0.1.1
type DirectoryRecord struct {
Config GroupConfig
Member *Member
}
DirectoryRecord joins a discoverable group configuration with the caller's own non-removed membership/application record when one exists.
type EligibilityChange ¶
type ErrorDetail ¶ added in v0.1.1
func (*ErrorDetail) Error ¶ added in v0.1.1
func (e *ErrorDetail) Error() string
func (*ErrorDetail) Unwrap ¶ added in v0.1.1
func (e *ErrorDetail) Unwrap() error
type Event ¶
type Event struct {
SpecVersion string `json:"specversion"`
ID string `json:"id"`
Source string `json:"source"`
Type string `json:"type"`
Subject string `json:"subject"`
TraceParent string `json:"traceparent,omitempty"`
Time time.Time `json:"time"`
Revision int64 `json:"revision"`
Data json.RawMessage `json:"data"`
// contains filtered or unexported fields
}
func (Event) RevisionSubject ¶ added in v0.1.1
RevisionSubject selects the object stream while the inbox hashes the original envelope.
type Facts ¶
type Facts struct {
StudentKnown bool
StageKnown bool
Bound bool
Student bool
Alumni bool
Temporary bool
Fields map[string]CardField
}
Facts contains current eligibility and card disclosure decisions supplied by backend. Bound is true only when all three independent QQ bindings are currently complete.
type FactsProvider ¶
type FactsProvider interface {
GroupFacts(ctx context.Context, principal account.Principal, owner, school string) (Facts, error)
}
FactsProvider is owned by groups; backend implements all provider mappings. Unknown stages and provider failures must not be turned into valid eligibility.
type GroupConfig ¶
type GroupConfig struct {
GroupSettings
Number string `json:"number"`
Revision int64 `json:"revision"`
PasswordSet bool `json:"password_set"`
PasswordEpoch int64 `json:"password_epoch,omitempty"`
}
type GroupConfigInput ¶
type GroupConfigInput struct {
GroupSettings
Number *string `json:"number,omitempty"`
ExpectedRevision int64 `json:"expected_revision"`
Password *string `json:"password,omitempty"`
}
type GroupCounts ¶
type GroupCounts struct{ Members, Pending int64 }
type GroupSettings ¶
type GroupSettings struct {
Name string `json:"name"`
BotEnabled bool `json:"bot_enabled"`
Discoverable bool `json:"discoverable"`
Category string `json:"category"`
Description string `json:"description"`
PasswordHint string `json:"password_hint"`
Welcome string `json:"welcome"`
RulesTemplate string `json:"rules_template"`
CheckCard bool `json:"check_card"`
RemindCard bool `json:"remind_card"`
BlockLinks bool `json:"block_links"`
FrequencySeconds int64 `json:"frequency_seconds"`
FrequencyLimit int64 `json:"frequency_limit"`
WarningLimit int64 `json:"warning_limit"`
ID string `json:"id"`
School string `json:"school"`
Mode string `json:"mode"`
RequireStudent bool `json:"require_student"`
AcceptAlumni bool `json:"accept_alumni"`
AcceptTemporary bool `json:"accept_temporary"`
GraceSeconds int64 `json:"grace_seconds"`
ReminderSeconds int64 `json:"reminder_seconds"`
RetentionSeconds int64 `json:"retention_seconds"`
CardTemplate string `json:"card_template"`
AutoCard bool `json:"auto_card"`
DiceSides int64 `json:"dice_sides"`
MuteProbability int64 `json:"mute_probability"`
MuteSeconds int64 `json:"mute_seconds"`
CooldownSeconds int64 `json:"cooldown_seconds"`
Pity int64 `json:"pity"`
Keywords []string `json:"keywords"`
RepeatThreshold int64 `json:"repeat_threshold"`
AutoActions []string `json:"auto_actions"`
}
type GroupSummary ¶
type GroupSummary struct {
ID string `json:"id"`
School string `json:"school"`
Name string `json:"name"`
Number string `json:"number"`
MemberCount int64 `json:"member_count"`
BotEnabled bool `json:"bot_enabled"`
RequireStudent bool `json:"require_student"`
PendingCount int64 `json:"pending_count"`
Revision int64 `json:"revision"`
}
type IdentityResolver ¶
type IdentityResolver interface {
ResolveOwner(ctx context.Context, principal account.Principal, identity BotIdentity) (string, error)
ResolveBotIdentity(ctx context.Context, principal account.Principal, owner string, bot BotScope) (BotIdentity, error)
}
IdentityResolver is the backend bot bridge's consumer-owned port. The provider must check the current service identity, bot scope and binding on every call. Errors use groups sentinels (errors.Is); unavailable is never a missing binding.
type ManagedGroup ¶
ManagedGroup identifies a configured group; it deliberately omits card fields, messages, raw QQ identifiers and other membership data.
type Member ¶
type Member struct {
ID string `json:"id"`
Joined bool `json:"joined"`
Owner string `json:"owner"`
State string `json:"state"`
Deadline time.Time `json:"deadline"`
Reminder time.Time `json:"reminder"`
Password bool `json:"password"`
PasswordEpoch int64 `json:"password_epoch,omitempty"`
Exempt bool `json:"exempt"`
Extended bool `json:"extended"`
Failures int64 `json:"failures"`
LastPlay time.Time `json:"last_play"`
MutedUntil time.Time `json:"muted_until"`
}
type MemberQuery ¶ added in v0.1.1
type MessageQuery ¶ added in v0.1.1
type MyGroup ¶
type MyGroup struct {
ID string `json:"id"`
Name string `json:"name"`
School string `json:"school"`
Number string `json:"number"`
Joined bool `json:"joined"`
State string `json:"state"`
Deadline *time.Time `json:"deadline"`
RequiresPassword bool `json:"requires_password"`
PasswordHint string `json:"password_hint,omitempty"`
Eligibility string `json:"eligibility"`
MissingConditions []string `json:"missing_conditions"`
UnknownConditions []string `json:"unknown_conditions"`
NextActions []string `json:"next_actions"`
MissingCardFields []string `json:"missing_card_fields,omitempty"`
}
type OutboxReader ¶
type OutboxReader interface {
PendingOutbox(ctx context.Context, limit int, excludeSubjects []string) ([]Event, error)
ConfirmOutbox(ctx context.Context, id string) error
}
OutboxReader is a trusted backend relay port. Exclusions are applied in SQL before ordering and limiting. Confirm only after all consumers commit durably.
type Outcome ¶
Bot must deduplicate by Action.ID and query actual outcomes after timeouts. Lookup returns found=false only when no execution took place. Never guess success.
type OwnerGroupRecord ¶
type OwnerGroupRecord struct {
Config GroupConfig
Member Member
}
OwnerGroupRecord is internal repository data. Public owner queries still return only ManagedGroup; MyGroups explicitly projects a separate user-safe shape.
type ReadTx ¶ added in v0.1.1
type ReadTx interface {
Get(string, string, any) error
List(string, string, int) ([]Row, error)
QueryList(string, ListQuery) ([]Row, error)
PendingActions(string) (int, error)
PendingAdmissionKick(group, owner string) (bool, error)
GroupCounts([]string) (map[string]GroupCounts, error)
OwnerGroups(owner, cursor string, limit int, includeApplicants bool) (Page[ManagedGroup], error)
OwnerGroupRecords(owner, cursor string, limit int, includeApplicants bool) (Page[OwnerGroupRecord], error)
DirectoryGroups(owner, school, category, cursor string, limit int) ([]DirectoryRecord, error)
}
type Report ¶
type Report struct {
ID string `json:"id"`
Reporter string `json:"reporter"`
Target string `json:"target,omitempty"`
Message string `json:"message"`
Reason string `json:"reason"`
State string `json:"state"`
Analysis string `json:"analysis,omitempty"`
Suggestions []string `json:"suggestions,omitempty"`
Feedback string `json:"feedback,omitempty"`
ResolvedBy *Actor `json:"resolved_by,omitempty"`
Created *time.Time `json:"created,omitempty"`
Updated *time.Time `json:"updated,omitempty"`
}
type ReportQuery ¶ added in v0.1.1
type Repository ¶
type Result ¶
type Result struct {
ID string `json:"id"`
State string `json:"state"`
Action string `json:"action"`
Value int64 `json:"value"`
Detail string `json:"detail"`
MaxValue *int64 `json:"max_value,omitempty"`
Seconds *int64 `json:"seconds,omitempty"`
PityRemaining *int64 `json:"pity_remaining,omitempty"`
MissingFields []string `json:"missing_fields,omitempty"`
}
type Service ¶
type Service struct {
PlatformIdentity admin.Identity
Repo Repository
Auth Authorizer
Facts FactsProvider
FactsPrincipal account.Principal
Bot Bot
AI Analyzer
Now func() time.Time
Random func(int64) (int64, error)
// contains filtered or unexported fields
}
func (*Service) Blacklists ¶
func (*Service) CleanupFrequency ¶ added in v0.1.1
CleanupFrequency removes bounded pages of expired message rate-limit windows for group g.
func (*Service) CleanupIdempotency ¶ added in v0.1.1
func (s *Service) CleanupIdempotency(ctx context.Context, bucketName, cursor string, maxAge time.Duration) (string, error)
CleanupIdempotency removes bounded pages of expired idempotency receipts or batch_inputs (default 24h).
func (*Service) CleanupOutbox ¶ added in v0.1.1
CleanupOutbox deletes at most 100 confirmed historical outbox rows older than maxAge (default 24h). Unsent or held outbox rows are never deleted.
func (*Service) Configuration ¶
func (*Service) Configure ¶
func (s *Service) Configure(ctx context.Context, p account.Principal, key string, in GroupConfigInput) (GroupConfig, error)
func (*Service) Consume ¶
func (s *Service) Consume(ctx context.Context, event UpstreamEvent) error
Consume atomically records inbox/revision and reevaluates all affected groups. Source data only identifies the owner: current facts always come from Facts.
func (*Service) Deliveries ¶
func (*Service) Directory ¶ added in v0.1.1
func (s *Service) Directory(ctx context.Context, p account.Principal, q DirectoryQuery) (Page[DirectoryGroup], error)
Directory returns student-facing public cards for discoverable groups. Groups requiring student verification are shown only when the caller holds valid campus eligibility in that school; groups without student requirement remain publicly discoverable to authenticated users unless restricted by blacklist.
func (*Service) Execute ¶
Execute serializes claims before an external call. Interrupted calls remain unknown and are resolved via Lookup on the next invocation with the same ID.
func (*Service) Fanout ¶
Fanout consumes committed disposition events, independently queuing each enabled recipient. Delivery state is the recipient action's actual state.
func (*Service) GroupsForOwner ¶
func (s *Service) GroupsForOwner(ctx context.Context, owner account.Principal, cursor string, limit int) (Page[ManagedGroup], error)
GroupsForOwner is a trusted backend query, not an HTTP authorization bypass. It returns joined, non-removed memberships whose group configuration exists.
func (*Service) Ingest ¶
Ingest is a trusted backend boundary, never mounted as a public route. Only authenticated bot adapters may provide the actual group and sender.
func (*Service) MemberEvent ¶
MemberEvent receives verified group membership from the host bot adapter. A web application alone cannot claim that a QQ user has already joined.
func (*Service) MyGroups ¶
func (s *Service) MyGroups(ctx context.Context, p account.Principal, cursor string, limit int) (Page[MyGroup], error)
MyGroups shares the indexed reverse lookup behind GroupsForOwner, including active applications. The only owner is the authenticated principal; no caller supplied owner, admin scope, or content fields enter the response.
func (*Service) QueryActions ¶ added in v0.1.1
func (*Service) QueryMembers ¶ added in v0.1.1
func (*Service) QueryMessages ¶ added in v0.1.1
func (*Service) QueryReports ¶ added in v0.1.1
func (*Service) Recover ¶
Recover is called by the host for expired execution leases, with bounded pages.
func (*Service) Subscriptions ¶
func (*Service) Sweep ¶
Sweep is a bounded host job for qualification deadlines and reminders. Host persists its cursor and periodically starts at the beginning for new deadlines.
type Subscription ¶
type UpstreamEvent ¶
type UpstreamEvent struct {
SpecVersion string `json:"specversion"`
ID string `json:"id"`
Source string `json:"source"`
Type string `json:"type"`
Subject string `json:"subject"`
TraceParent string `json:"traceparent,omitempty"`
Time time.Time `json:"time"`
DataContentType string `json:"datacontenttype"`
SchoolID string `json:"schoolid,omitempty"`
Data EligibilityChange `json:"data"`
}
UpstreamEvent uses the providers' public CloudEvents shape. Preserve source and subject: verification uses object streams; qq-binding uses an owner stream.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package accountquery provides the module-owned account investigation port.
|
Package accountquery provides the module-owned account investigation port. |
|
Package httpapi accepts principals only from the host authentication middleware.
|
Package httpapi accepts principals only from the host authentication middleware. |
|
Package postgres owns all groups SQL.
|
Package postgres owns all groups SQL. |
|
Package sdk provides primitives to interact with the openapi HTTP API.
|
Package sdk provides primitives to interact with the openapi HTTP API. |