go-core is the Core SDK for Standards Lab's Go Elemental standard. It provides layered configuration, a dependency graph and the process lifecycle that runs it, a reactor that joins a source of occurrences to a handler, the CloudEvents envelope a domain raises its events in, a server-sent event stream reader and writer, and logging.
github.com/standards-lab/go-core is a single Go module with the process-level packages every
program in the standard builds on.
go-core is the Core SDK of
Go Elemental, the
minimal-dependency Go standard. This README and each package's doc.go document the
repository; the standard's principles it enhances are stated below.
It enhances the standard's dependency line: where Go Elemental admits packages as idiomatic and
stable as the standard library, this repository depends on the standard library alone.
config— loads configuration in layers: a base file, an environment overlay, and secrets.event— the CloudEvents 1.0 envelope, its binary-content-mode codec (Encode,Decode) and its JSON-format codec (EncodeJSON,DecodeJSON), and the types a domain raises its events with: anEventKinddeclared withDefineraises an event into aQueue, carrying the extension attributes the raise'sRaiseOptionssets, and aRecorderemits the queue through aSinkinto the command's own transaction, only when the command succeeds. The recorder also stamps every event with the service-wide extension attributes itsOptionsset; when a raise sets the same name, the raise's value wins.Permanentmarks a handler's error that redelivery cannot fix.graph— a typed dependency graph: nodes described inertly, each a name and a constructor, placed at definition after other nodes or in groups, and a Build that constructs what the roots reach into a System of computed layers.ValueandFreshdefine fixed and per-Build values, and a System names its nodes by their handles. A Graph is safe for concurrent use.docs/graph-design.mdgives the reasons behind the design ofgraphandlifecycle.graph/graphtest— the test toolkit besidegraph:CheckNameschecks a struct of node and group handles against the names its nodes and groups were defined with.lifecycle— runs a builtgraphSystem: starts its layers in order, tracks and reports readiness, watches for runtime failures, and shuts the layers down in reverse within a timeout. A value takes part through the interfaces it implements.Execis the one-shot form a CLI command uses;Runis the long-running form a service uses.logging— builds an*slog.Loggerfrom a configuration thatconfigloads.process— the parts of a binary's main sequence that run before the program's own infrastructure exists: the signal-derived root context, pre-logger failure reporting, and the exit-code convention.process/processtest— the integration toolkit: it builds a program once per suite run and runs it as a subprocess. It then waits on what a client observes, interrupts the process and reads its exit code, and relays a backing service's connection so a test can sever it.Runruns the program once and returns its stdout, stderr, and exit code.reactor— joins one source of occurrences to one function for the process lifetime: a lifecycle component that drains the handling in flight at shutdown and cancels it once theOptions.CancelAfterperiod passes.Everydelivers on an interval, andWakealso delivers on eachWaker.Nudgea producer calls.Gatepauses background work while an operation runs exclusively.sse— reads and writes a server-sent event stream, the WHATWGtext/event-streamformat.NewDecoderreads anyio.Readeras its bytes arrive and returns aDecoderwhoseNextreturns each dispatchedEvent, its type, data, and last event ID, and whoseRetryreports the reconnection time the stream last set.NewEncoderwrites to anyio.Writerand returns anEncoderwhoseEncode,Comment, andRetryeach send their lines in oneWrite, so an HTTP writer can flush once per event.
Tasks run through mise:
mise run check # build, vet, format, fix, tidy, test, and lint, then lint-context and lint-references; writes nothing
mise run currency # report tools, Go, requirements, and action pins behind their latest, a held one with its reason
mise run upgrade # move every trailing pin but a held one: tools, the go directive, requirements, and action pins
mise run fmt # format all Go source
mise run tidy # run go mod tidy