work

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package work is the engine's commands and reads on ideas and pursuits: each change one command in one transaction with its event. An idea belongs to the person who adds it and has no named states; a pursuit is started against a signal, with an appetite or none, is active, done or stopped, and an idea has at most one active pursuit.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownIdea    = errors.New("unknown idea")
	ErrUnknownPursuit = errors.New("unknown pursuit")
	ErrSlugTaken      = errors.New("slug taken")
	ErrSlugInvalid    = errors.New("slug invalid")
	ErrActivePursuit  = errors.New("idea already has an active pursuit")
	ErrNotActive      = errors.New("pursuit not active")
	ErrBadAppetite    = errors.New("bad appetite")
	ErrNoPerson       = errors.New("no person")
	ErrNoText         = errors.New("no text")
	ErrSignal         = errors.New("signal incomplete")
)

The kinds of Refusal. Test one with errors.Is; the API replies bad_request to every Refusal, with its message.

Functions

func MakeSlug

func MakeSlug(text string) string

MakeSlug makes a slug from an idea's text: its first words in lower-case ASCII letters and digits, joined by "-", at most 5 words and 40 characters. Text with no such word gives "idea". The slug may be reserved or taken; the command that stores it makes it unique.

func ValidSlug

func ValidSlug(s string) error

ValidSlug says why s cannot be a slug a person chose, or nil when it can: lower-case letters and digits in words joined by "-", at most 40 characters, and not the name of a subcommand. Whether it is taken is the command's check.

Types

type IdeaDetail

type IdeaDetail struct {
	IdeaFacts
	Pursuits []PursuitFacts
}

IdeaDetail is an idea with its pursuits, newest first.

func Idea

func Idea(ctx context.Context, s Submitter, slug string) (IdeaDetail, error)

Idea returns one idea with its pursuits, or refuses naming an unknown slug.

type IdeaFacts

type IdeaFacts struct {
	Slug, Text, Person    string
	CreatedAt             time.Time
	Pursuit, PursuitState string
}

IdeaFacts is an idea and the facts that say where it stands. Pursuit and PursuitState are its latest pursuit's, empty when it has none.

func AddIdea

func AddIdea(ctx context.Context, s Submitter, in IdeaIn) (IdeaFacts, error)

AddIdea adds an idea owned by in.Person, with event idea.added. A slug made from the text gets a number when it is taken or reserved; a chosen slug that is taken is refused.

func Ideas

func Ideas(ctx context.Context, s Submitter) ([]IdeaFacts, error)

Ideas returns every idea, newest first.

type IdeaIn

type IdeaIn struct {
	Text, Slug, Person string
}

IdeaIn adds an idea. Slug is optional: left empty, one is made from Text.

type PursueIn

type PursueIn struct {
	Slug     string
	Appetite int64
	Signal   signal.Signal
	Person   string
}

PursueIn starts a pursuit of an idea against Signal. Appetite 0 is none.

type PursuitDetail

type PursuitDetail struct {
	PursuitFacts
	Signal *signal.Signal
}

PursuitDetail is a pursuit with its signal, nil for a pursuit started before signals were recorded.

func Pursuit

func Pursuit(ctx context.Context, s Submitter, slug string) (PursuitDetail, error)

Pursuit returns one pursuit with its signal, or refuses naming an unknown slug.

func StartPursuit

func StartPursuit(ctx context.Context, s Submitter, in PursueIn) (PursuitDetail, error)

StartPursuit starts a pursuit of an idea, with event pursuit.started carrying its appetite and signal. The signal is required whole and checked on the engine's day: its window is today or later. An appetite is optional; with none there is no circuit breaker. An idea with an active pursuit is refused another. The pursuit's slug is the idea's, numbered when an earlier pursuit has it.

func StopPursuit

func StopPursuit(ctx context.Context, s Submitter, in StopIn) (PursuitDetail, error)

StopPursuit stops an active pursuit, with event pursuit.stopped. Only an active pursuit stops; the reason is kept, or "stopped by <person>" when none is given.

type PursuitFacts

type PursuitFacts struct {
	Slug, Idea, IdeaText, Person string
	Appetite, Spent              int64
	State, StopReason            string
	CreatedAt, StartedAt         time.Time
	EndedAt                      time.Time
}

PursuitFacts is a pursuit: its idea, appetite and spend in tokens, state and times. Appetite is 0 when the pursuit has none. StopReason, StartedAt and EndedAt are empty or zero when unset.

func Pursuits

func Pursuits(ctx context.Context, s Submitter) ([]PursuitFacts, error)

Pursuits returns every pursuit, newest first.

type Refusal

type Refusal struct {
	Kind error
	Msg  string
}

Refusal is a command or read refused for what it was asked, not for a fault: its message says why in plain words, naming the slug.

func (*Refusal) Error

func (r *Refusal) Error() string

func (*Refusal) Unwrap

func (r *Refusal) Unwrap() error

type StopIn

type StopIn struct {
	Slug, Reason, Person string
}

StopIn stops an active pursuit. Reason empty is "stopped by <person>".

type Submitter

type Submitter interface {
	Submit(ctx context.Context, c state.Command) error
}

Submitter runs a command in one transaction; *state.State is one.

Jump to

Keyboard shortcuts

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