api

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 24 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 api is the Go port of lib/tasks/api — the loopback HTTP surface described by docs/api/openapi.yaml.

It is an ADAPTER and nothing else. Every rule about tasks lives in internal/application and internal/store; what happens here is transport: routing, host and origin enforcement, body and query validation, the If-Match precondition, the JSON envelope, and the mapping from the shared outcome vocabulary onto HTTP status codes.

Concurrency is this surface's distinguishing risk. Unlike the CLI, one process serves many requests against one pair of files, so every handler builds its own store through a factory, holds no cross-request state, and relies on the store's own lock and revision preconditions rather than on any coordination invented here. The Server value itself is immutable after construction apart from the mutex that serializes its log sink.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Changesets

type Changesets interface {
	ApplyChangeset(changeset store.Changeset) store.MutationResult
}

Changesets applies one atomic multi-field change under the store's lock.

type CheckedRead

type CheckedRead struct {
	Queries  *taskquery.Queries
	Revision string
	Status   store.Status
	Errors   []store.Entry
}

CheckedRead is one coherent checked read: the read model over the snapshot, the global revision of the exact bytes behind it, and the store's verdict on those bytes.

func (CheckedRead) OK

func (r CheckedRead) OK() bool

OK reports bytes this build may interpret.

type Options

type Options struct {
	// App is the shared facade every rule about tasks goes through.
	App *application.Application

	// Read is the coherent checked read every store-backed GET uses. See
	// seams.go for why it is not a method on App yet.
	Read Reader

	// Changesets applies an atomic multi-field PATCH. A nil value makes PATCH
	// refuse with 501 rather than silently degrade to a single-field write.
	Changesets func() Changesets

	// TemporalContext is the clock and zone every request reads.
	TemporalContext func() temporal.Context

	Port       int
	MaxDepth   int
	UrgentDays int
	Timezone   string
	TimeFormat int

	// QueryOptions are the link shorthands and systems every read model built
	// here is configured with, so an HTTP resource and `tasks links` classify a
	// URL the same way.
	QueryOptions []taskquery.Option

	// Logger receives one JSON line per request. nil disables logging.
	Logger io.Writer

	// RequestIDs and Clock are injectable so a test can pin both halves of the
	// log line and the error envelope.
	RequestIDs func() string
	Clock      func() time.Time
}

Options is the immutable construction settings of one server.

type Reader

type Reader func() (CheckedRead, error)

Reader performs one checked read. Every request that answers from the store calls it exactly once, so no response can mix two reads.

func NewStoreReader

func NewStoreReader(factory func() *store.Store, context func() temporal.Context,
	options ...taskquery.Option) Reader

NewStoreReader builds the production Reader over a store factory. The factory yields a FRESH store per call for the same reason application.StoreFactory does: a concurrent request must not be handed a neighbour's store.

type Server

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

Server is the http.Handler. Everything it holds is immutable after construction except the log mutex, which exists because the ONE thing this adapter genuinely shares between concurrent requests is the log sink.

func New

func New(options Options) (*Server, error)

New validates the options and builds a server.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(writer http.ResponseWriter, request *http.Request)

Jump to

Keyboard shortcuts

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