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

state

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package state describes a service's migration state: the modules a migration moves, the IO each performs, and how far each has got.

Index

Constants

View Source
const Library = "library"

Library is the node type of shared code that performs no IO.

Variables

This section is empty.

Functions

This section is empty.

Types

type Catalog added in v0.40.0

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

Catalog is every kind of IO that the protocol servers in one binary support.

func NewCatalog added in v0.40.0

func NewCatalog(supports ...Support) (*Catalog, error)

NewCatalog collects what protocol servers support, grouped by protocol with ingress first, so listings are stable. A kind supported twice is an error.

func (*Catalog) Support added in v0.40.0

func (c *Catalog) Support(kind model.IOKind) (Support, bool)

Support returns what the catalog supports for kind, if it supports it.

func (*Catalog) Supports added in v0.40.0

func (c *Catalog) Supports() []Support

Supports returns every supported kind of IO in listing order.

type Config added in v0.36.0

type Config struct {
	// StateFile is the path to the migration state TOML file.
	StateFile string `default:"spectre/state.toml" type:"path" help:"Path to the migration state TOML file."`
}

Config locates the migration state file.

type InvalidError added in v0.36.0

type InvalidError struct {
	Problems []Problem
}

InvalidError lists every problem that makes a migration state invalid.

func (*InvalidError) Error added in v0.36.0

func (e *InvalidError) Error() string

Error returns the first problem and how many more there are.

type Node added in v0.36.0

type Node struct {
	ID        string
	DependsOn []string
	Status    Status
	// IO holds the settings of each IO kind the node has. A library has none.
	IO map[model.IOKind]map[string]any
	// Line is where the node's table starts in the file, or 0 when unknown.
	Line int
}

Node is one module of the service.

type NodeType

type NodeType struct {
	// Name is how the type is referred to, e.g. "library" or "ingress[http]".
	Name string `json:"name"`
	// Description says what code has the type and how to recognise it.
	Description string `json:"description"`
	// Table is where a node of an IO kind holds its settings, or empty for library.
	Table string `json:"table,omitzero"`
	// Settings are the fields the table can hold.
	Settings []Setting `json:"settings,omitzero"`
}

NodeType is a type that a node in the migration state can have.

func NodeTypes

func NodeTypes(catalog *Catalog) []NodeType

NodeTypes returns library, then each kind of IO the catalog supports.

type Problem added in v0.36.0

type Problem struct {
	// Line is where the problem is in the file, or 0 when unknown.
	Line    int
	Message string
}

Problem is one thing wrong with a migration state.

func (Problem) String added in v0.36.0

func (p Problem) String() string

String returns the problem prefixed with its line, if known.

type Setting added in v0.40.0

type Setting struct {
	Name        string `json:"name"`
	Required    bool   `json:"required"`
	Description string `json:"description"`
	// Key describes what keys the entries, or is empty for a plain value.
	Key string `json:"key,omitzero"`
	// Unique keyed entries may belong to only one node, such as a route.
	Unique bool `json:"unique,omitzero"`
	// Entry lists the settings that each entry takes.
	Entry []Setting `json:"entry,omitzero"`
}

Setting is one field that a node's table for a kind of IO can hold. With a Key, it is a table of entries, each holding the Entry settings.

type State added in v0.36.0

type State struct {
	// Nodes are the service's modules, sorted by ID.
	Nodes []Node
}

State is a service's migration state.

func Load added in v0.36.0

func Load(path string, catalog *Catalog) (State, error)

Load reads and parses the migration state file at path.

func Parse added in v0.36.0

func Parse(data []byte, catalog *Catalog) (State, error)

Parse reads a migration state and checks it against the IO kinds the catalog supports. An invalid state returns an *InvalidError.

func (State) Unreached added in v0.36.0

func (s State) Unreached() []Problem

Unreached returns a warning for each node that no ingress node is or depends on, since ingress traffic never reaches its code.

type Status added in v0.36.0

type Status string

Status says where a node's code lives.

const (
	// Pending code is only in the reference.
	Pending Status = "pending"
	// Migrated code is in the candidate as well as the reference.
	Migrated Status = "migrated"
)

type Support added in v0.40.0

type Support struct {
	Kind        model.IOKind
	Description string
	Settings    []Setting
}

Support is a kind of IO that a protocol server proxies, with a description of the code that performs it and the settings a migration state node of it takes.

Jump to

Keyboard shortcuts

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