Documentation
¶
Overview ¶
Package calendar provides event scheduling with recurrence rules and per-attendee RSVP state — distinct from kit/scheduler (in-process fire-once / cron) by modelling human time semantics: invitations, RSVP states, attendee caps, organiser permissions, named recurrence rules.
Use cases: game guild events, on-call rotations, meeting bookings, scheduled trading rebalances. The package ships an in-memory Manager for tests and a clean interface for PG-backed implementations.
Index ¶
- Variables
- type AttendeeID
- type Event
- type EventID
- type EventOccurrence
- type Invitation
- type InviteID
- type Manager
- type MemoryConfig
- type MemoryManager
- func (m *MemoryManager) CancelEvent(_ context.Context, id EventID) error
- func (m *MemoryManager) CreateEvent(_ context.Context, e Event) (EventID, error)
- func (m *MemoryManager) GetEvent(_ context.Context, id EventID) (Event, error)
- func (m *MemoryManager) Invitations(_ context.Context, eventID EventID) ([]Invitation, error)
- func (m *MemoryManager) Invite(_ context.Context, eventID EventID, attendees ...AttendeeID) ([]Invitation, error)
- func (m *MemoryManager) Occurrences(_ context.Context, id EventID, from, to time.Time) ([]time.Time, error)
- func (m *MemoryManager) Respond(_ context.Context, invite InviteID, state RSVPState) error
- func (m *MemoryManager) Uninvite(_ context.Context, invite InviteID) error
- func (m *MemoryManager) Upcoming(ctx context.Context, attendee AttendeeID, within time.Duration) ([]EventOccurrence, error)
- func (m *MemoryManager) UpdateEvent(_ context.Context, e Event) error
- type RSVPState
- type Recurrence
- type RuleKind
Constants ¶
This section is empty.
Variables ¶
var ( ErrEventNotFound = errors.New("calendar: event not found") ErrInviteNotFound = errors.New("calendar: invitation not found") ErrAtCapacity = errors.New("calendar: event at attendee capacity") ErrCustomRRULENotSupported = errors.New("calendar: RuleCustom requires a consumer-supplied expander") )
Errors surfaced by the manager.
Functions ¶
This section is empty.
Types ¶
type AttendeeID ¶
type AttendeeID string
EventID, InviteID, and AttendeeID are opaque caller-meaningful identifiers.
type Event ¶
type Event struct {
ID EventID
Organiser AttendeeID
Title string
Description string
Start, End time.Time
Recurrence Recurrence
MaxAttendees int // 0 = unlimited
Meta map[string]any
}
Event is the canonical event entity.
type EventID ¶
type EventID string
EventID, InviteID, and AttendeeID are opaque caller-meaningful identifiers.
type EventOccurrence ¶
EventOccurrence is an expanded recurring-event instance.
type Invitation ¶
type Invitation struct {
ID InviteID
Event EventID
Attendee AttendeeID
State RSVPState
InvitedAt time.Time
RespondedAt *time.Time
}
Invitation joins an event with an attendee + RSVP state.
type InviteID ¶
type InviteID string
EventID, InviteID, and AttendeeID are opaque caller-meaningful identifiers.
type Manager ¶
type Manager interface {
CreateEvent(ctx context.Context, e Event) (EventID, error)
UpdateEvent(ctx context.Context, e Event) error
CancelEvent(ctx context.Context, id EventID) error
GetEvent(ctx context.Context, id EventID) (Event, error)
Invite(ctx context.Context, eventID EventID, attendees ...AttendeeID) ([]Invitation, error)
Respond(ctx context.Context, invite InviteID, state RSVPState) error
Uninvite(ctx context.Context, invite InviteID) error
Invitations(ctx context.Context, eventID EventID) ([]Invitation, error)
Occurrences(ctx context.Context, id EventID, from, to time.Time) ([]time.Time, error)
Upcoming(ctx context.Context, attendee AttendeeID, within time.Duration) ([]EventOccurrence, error)
}
Manager is the canonical surface; the in-memory implementation satisfies it. PG-backed adapters are pluggable behind the same signature.
type MemoryConfig ¶
MemoryConfig configures MemoryManager.
type MemoryManager ¶
type MemoryManager struct {
// contains filtered or unexported fields
}
MemoryManager is an in-process Manager. Goroutine-safe.
func NewMemoryManager ¶
func NewMemoryManager(cfg MemoryConfig) *MemoryManager
NewMemoryManager constructs a MemoryManager.
func (*MemoryManager) CancelEvent ¶
func (m *MemoryManager) CancelEvent(_ context.Context, id EventID) error
CancelEvent removes the event and all of its invitations.
func (*MemoryManager) CreateEvent ¶
CreateEvent stores e. If e.ID is empty, a fresh id is assigned.
func (*MemoryManager) Invitations ¶
func (m *MemoryManager) Invitations(_ context.Context, eventID EventID) ([]Invitation, error)
Invitations returns every invitation for an event.
func (*MemoryManager) Invite ¶
func (m *MemoryManager) Invite(_ context.Context, eventID EventID, attendees ...AttendeeID) ([]Invitation, error)
Invite issues invitations to one or more attendees. Honors MaxAttendees.
func (*MemoryManager) Occurrences ¶
func (m *MemoryManager) Occurrences(_ context.Context, id EventID, from, to time.Time) ([]time.Time, error)
Occurrences expands a recurring event between [from, to].
func (*MemoryManager) Uninvite ¶
func (m *MemoryManager) Uninvite(_ context.Context, invite InviteID) error
Uninvite removes an invitation.
func (*MemoryManager) Upcoming ¶
func (m *MemoryManager) Upcoming(ctx context.Context, attendee AttendeeID, within time.Duration) ([]EventOccurrence, error)
Upcoming returns occurrences within [now, now+within] for events where attendee has an accepted/tentative invitation.
func (*MemoryManager) UpdateEvent ¶
func (m *MemoryManager) UpdateEvent(_ context.Context, e Event) error
UpdateEvent replaces an existing event.
type Recurrence ¶
type Recurrence struct {
Rule RuleKind
Until *time.Time // optional end date (inclusive)
Count *int // optional max occurrence count (counted from Start)
RRule string // only used when Rule == RuleCustom
}
Recurrence describes how an event repeats.