Help us shape the future of Go! Take the 2026 Go Developer Survey

segments

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package segments is the Segment domain module: named Conditions on Contacts, with the rows they select and the live work that uses them.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidCondition: the condition does not parse or does not fit the
	// Contact schema. The wrapped message is safe to show to the author.
	ErrInvalidCondition = validation.Refuse("segments: invalid condition", "errors.segment_condition_invalid")
	// ErrNotFound: no such Segment in this Workspace.
	ErrNotFound = validation.Refuse("segments: segment not found", "errors.segment_not_found")
)

Domain errors returned by Module. Callers match with errors.Is.

Functions

func UsingTag

func UsingTag(ctx context.Context, s *ent.Scoped, name string) ([]*ent.Segment, error)

UsingTag returns the Workspace's Segments whose Condition names the Tag by its name, in id order. Archived ones count: restoring one must not leave it naming a missing Tag. A Condition keeps the name, not an id, so deleting the Tag would leave it matching nothing.

Types

type CreateInput

type CreateInput struct {
	Name      string
	Condition *string
}

CreateInput is a new Segment. A nil or empty Condition means "no rules yet".

type Module

type Module struct {
	// contains filtered or unexported fields
}

Module is the one place a Segment is written, validated, previewed and counted (ADR 0016). Create and update share one validation rule set; handlers stay thin adapters (scope check, call, map). Membership is the rule alone — Send-eligibility is subtracted only at send, never folded into a count (ADR 0001).

func New

func New(bus *events.Bus) *Module

New builds the Segments module. It holds no client: every call takes the Workspace's scoped client (ADR 0017); the bus runs the archive in one transaction.

func (*Module) Archive

func (s *Module) Archive(ctx context.Context, ws *ent.Scoped, id int64) error

Archive discards a Segment (ADR 0049), unless a draft or scheduled Broadcast uses it: then it returns an *inuse.Error naming those Broadcasts. A sent or failed Broadcast keeps its stored reference as history and does not block. A missing Segment is ErrNotFound; archiving an archived one changes nothing.

func (*Module) Contacts

func (s *Module) Contacts(ctx context.Context, ws *ent.Scoped, id int64, p pagination.Params) (pagination.Page[*ent.Contact], error)

Contacts returns one page of the Contacts a stored Segment matches, evaluated live, ascending by id.

func (*Module) Count

func (s *Module) Count(ctx context.Context, ws *ent.Scoped, id int64) (int, error)

Count counts the Contacts matching a stored Segment, evaluated live.

func (*Module) Create

func (s *Module) Create(ctx context.Context, ws *ent.Scoped, in CreateInput) (*ent.Segment, error)

Create validates the condition and stores the Segment.

func (*Module) Get

func (s *Module) Get(ctx context.Context, ws *ent.Scoped, id int64) (*ent.Segment, error)

Get returns one Segment. An unknown id is ErrNotFound.

func (*Module) List

func (s *Module) List(ctx context.Context, ws *ent.Scoped, p pagination.Params, archived bool) (pagination.Page[*ent.Segment], error)

List returns one page of the Workspace's Segments, ascending by id: the kept ones, or with archived the archived ones.

func (*Module) Preview

func (s *Module) Preview(ctx context.Context, ws *ent.Scoped, cond string) (int, error)

Preview counts the Contacts in the Workspace that match an unsaved condition.

func (*Module) Unarchive

func (s *Module) Unarchive(ctx context.Context, ws *ent.Scoped, id int64) error

Unarchive brings an archived Segment back to the lists. Restoring one that is not archived changes nothing; a missing Segment is ErrNotFound.

func (*Module) Update

func (s *Module) Update(ctx context.Context, ws *ent.Scoped, id int64, in UpdateInput) (*ent.Segment, error)

Update validates a changed condition exactly as Create does, then applies the change.

func (*Module) Validate

func (s *Module) Validate(ctx context.Context, ws *ent.Scoped, cond string) error

Validate checks a condition against the Contact attributes and the Workspace's Custom field catalogue. An empty condition is valid. This is the single rule set behind Create, Update, Preview and Count.

type UpdateInput

type UpdateInput struct {
	Name      *string
	Condition *string
}

UpdateInput changes a Segment; nil fields are left as they are.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL