common

package
v0.9.12 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 5 Imported by: ? 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

Index

Constants

View Source
const (
	ContextKeyAPIRequestInfo  = "_api_request_info"
	ContextKeyAPIResponseInfo = "_api_response_info"
	ContextKeyAPIError        = "_api_error"

	ContextKeyCredential = "_credential"
	ContextKeySession    = "_session"
	ContextKeyNamespace  = "_namespace"
	ContextKeyDB         = "_db"
	ContextKeyTX         = "_tx"
	ContextKeyLogger     = "_logger"
	ContextKeyTrace      = "_trace"
	ContextKeyConfig     = "_config"
)
View Source
const (
	RedactMask = "REDACTED XXXX"
)
View Source
const (
	TimeFormat = "2006-01-02 15:04:05.00"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Daemon

type Daemon interface {
	Start(ctx context.Context) error
	Stop(ctx context.Context) error
}

Daemon may be started and stopped repeatedly on one instance. What a start runs lives until Stop: Start's ctx bounds the start alone and is never kept, its values aside. Stop refuses new work, cancels and awaits the rest (an earlier Stop's leftovers included) until ctx ends, then forces what it can and returns an error wrapping ctx's; it returns only after intake has stopped, and leftovers must not reach a later Start.

type Debuggable

type Debuggable interface {
	Info(w io.Writer, debug bool)
}

type DependencyState added in v0.9.5

type DependencyState int

DependencyState is what a dependency has become, as the supervisor tells a dependent that runs on beside it.

const (
	// DependencyRunning: the dependency runs again, and has forgotten what was
	// registered with it before it stopped.
	DependencyRunning DependencyState = iota + 1
	// DependencyStopped: the dependency has stopped, by hand or for a restart,
	// and has forgotten what was registered with it.
	DependencyStopped
	// DependencyFailed: the dependency's Init or Start failed; it is down until
	// a restart succeeds, which DependencyRunning then says.
	DependencyFailed
)

func (DependencyState) String added in v0.9.5

func (s DependencyState) String() string

type Initializable

type Initializable interface {
	Init(ctx context.Context) error
}

Init runs at the first start and every restart: resolve the reloadable settings here (design/config.md).

type Liveness added in v0.3.0

type Liveness interface {
	Alive(ctx context.Context) error
}

Probes honour the caller's ctx deadline; an implementation may only tighten it.

type Message added in v0.2.16

type Message interface {
	Kind() string
}

type MessageHandler added in v0.2.16

type MessageHandler interface {
	Named
	HandleMessage(ctx context.Context, msg Message) error
}

MessageHandler's name is its subscription; it need not be a Service.

type MessageSender added in v0.2.16

type MessageSender interface {
	Service
	SendMessage(ctx context.Context, from Named, msg Message)
}

type Named

type Named interface {
	Name() string
}

type Pair

type Pair[K comparable, V any] interface {
	SetKey(key K)
	SetValue(value V)
	GetKey() K
	GetValue() V
	String() string
}

func NewPair

func NewPair[K comparable, V any](key K, value V) Pair[K, V]

func ParsePair

func ParsePair(s string) (Pair[string, string], bool)

type Pairs

type Pairs []Pair[string, string]

func NewPairs

func NewPairs[T Pair[string, string]](src []T) Pairs

func ParsePairs

func ParsePairs(s string) (Pairs, bool)

func ParsePairsMap

func ParsePairsMap(m map[string]string) Pairs

func (Pairs) Map

func (p Pairs) Map() map[string]string

func (Pairs) String

func (p Pairs) String() string

type RawMessageHandler added in v0.2.16

type RawMessageHandler interface {
	Named
	HandleRawMessage(ctx context.Context, kind string, payload any) error
}

RawMessageHandler receives every message, typed or raw.

type RawMessageSender added in v0.2.16

type RawMessageSender interface {
	Service
	SendRawMessage(ctx context.Context, from Named, kind string, payload any)
}

type Readiness added in v0.3.0

type Readiness interface {
	Ready(ctx context.Context) error
}

type Reconcilable added in v0.9.5

type Reconcilable interface {
	Reconcile(ctx context.Context, dep Service, state DependencyState) error
}

Reconcilable is a service that registers something with a dependency, a subscription or a task, which the dependency forgets when it stops. When the supervisor stops or starts that dependency alone, it calls Reconcile on each such dependent that keeps running, in dependency order, under its lock: Reconcile brings what dep holds for this service in line with state, putting back on DependencyRunning what this service holds, and nothing else. It relies on no state but the one it is given: a call that finds nothing to do changes nothing, and a state it does not act on returns nil. It runs beside the service's own work, bounded by ctx, so it registers and never does slow work, nor calls the supervisor. An error fails the service, which the supervisor then restarts, its own Init and Start registering everything.

type Service

type Service interface {
	Named
	// Dependencies are initialized and started first; nil entries are skipped.
	Dependencies() []Service
}

type Unique

type Unique interface {
	Key() string
}

type Weighted

type Weighted interface {
	Priority() int
	SetPriority(priority int)
}

Jump to

Keyboard shortcuts

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