Reference / Config API for Go
Config API for Go
Every public type, function and constant of the Config engine in tinyshed.org/tinystore, generated from its source. The Config guide explains how to use them, and the Bun and Node, Python and Rust pages list the same API.
Config
type Config[T any] struct {
// contains filtered or unexported fields
}Config is a program's settings as one typed value, read from memory, which a change of a live setting made in any process replaces whole.
OpenConfig
func OpenConfig[T any](ctx context.Context, store *Store, name string, defaults T, opts ...ConfigOption) (*Config[T], error)OpenConfig opens a config: defaults declare every setting, its type and its default, then each layer declares again what came before, in the order written, and a live setting's change, kept in the store, goes over them all. It opens once its layers are read, or fails with one Invalid error that lists every problem. The same open in the process shares one stream.
config, err := tinystore.OpenConfig(ctx, store, "app", Settings{Port: 8080},
tinystore.File("app.yaml"), tinystore.Env("APP", tinystore.Var("port", "PORT")))OpenConfigJSON
func OpenConfigJSON(
ctx context.Context, store *Store, name string, declaration json.RawMessage, opts ...ConfigOption,
) (*Config[map[string]any], error)OpenConfigJSON opens a config declared as data, its declaration the JSON every SDK sends: each setting with its kind, default, required, secret, live and rules, a group, a map of entries, or a group a text setting beside it chooses by name. Its value is a map whose secrets are Secret, durations time.Duration, integers int64 and numbers float64; layers, rules, secrets and Explain are as OpenConfig's. A declaration that means nothing is Invalid, naming where.
config, err := tinystore.OpenConfigJSON(ctx, store, "dashbin", declaration,
tinystore.File("dashbin.toml"), tinystore.Env("DASHBIN"))
port := config.Get()["instance"].(map[string]any)["aimee"].(map[string]any)["settings"].(map[string]any)["port"]Config.Explain
func (c *Config[T]) Explain() []LineExplain is every setting with its value, the layer that gave it and what it went over, newest first, as text and in Given as data; Notes is what was read and not used.
Config.Get
func (c *Config[T]) Get() TGet is the settings as they are now, a copy: read it where it is used.
Config.Notes
func (c *Config[T]) Notes() []stringNotes is what the config read and did not use, each with why: an optional file that was absent, a variable with the prefix that names no setting, a kept change left out, a value validate refused.
Config.Reset
func (c *Config[T]) Reset(ctx context.Context, path string) errorReset drops the change kept of the setting or the group at path, so that the layers give it again; a path with no setting and no change is Invalid.
Config.ResetAll
func (c *Config[T]) ResetAll(ctx context.Context) errorResetAll drops every change kept of the config.
Config.Update
func (c *Config[T]) Update(ctx context.Context, change func(*T), opts ...UpdateOption) errorUpdate changes live settings: change sets them on a copy of the value, and each setting it changed is kept in the store, over every layer until Reset, seen by every handle before Update returns, all of them or none. One that is not live is Invalid. A change raced by another runs change again on the newer value, unless IfVersion was given.
err = config.Update(ctx, func(s *Settings) { s.Limits.RPS = 200 })Config.Version
func (c *Config[T]) Version() int64Version is the version of the changes the value holds, which IfVersion takes.
Config.Watch
func (c *Config[T]) Watch(ctx context.Context) iter.Seq[T]Watch is the settings now, then after every change made in this process or another, whole and once committed; one that falls behind gets the newest. It ends when ctx ends or the store closes.
for s := range config.Watch(ctx) {
limiter.SetRate(s.Limits.RPS)
}ConfigOption
type ConfigOption interface {
// contains filtered or unexported methods
}ConfigOption is a layer of a config after its declaration, or how it opens.
Env
func Env(prefix string, opts ...EnvOption) ConfigOptionEnv reads the environment: prefix_ and each setting's path in upper snake case, APP_LIMITS_RPS for limits.rps, a list as a,b,c or JSON and a map as JSON. NAME_FILE reads the setting from that file, as Docker and Kubernetes pass secrets; a variable with the prefix that names no setting is said.
File
func File(path string, opts ...FileOption) ConfigOptionFile is a TOML, YAML or JSON file the config reads, by its extension: .toml, .yaml or .yml, .json or .jsonc, JSON taking comments and a trailing comma. A relative path is the working directory's; one that does not exist is Invalid unless Optional.
Strict
func Strict() ConfigOptionStrict fails the open while a kept change no longer fits the declaration, rather than ignoring it: for a config whose defaults are worse than not starting.
Validate
func Validate[T any](check func(T) error) ConfigOptionValidate checks the whole value at open and before a change is kept: a change it refuses keeps nothing. What relates two settings, a format or a pattern, is its; T is the config's.
Entries
type Entries[T any] map[string]TEntries is a map of named entries, each a T struct whose fields are settings of their own, with their own tags: a file gives an entry field by field, and APP_INSTANCE_AIMEE_PASSWORD, or its _FILE, one field of the entry aimee that a layer before it made. A field a layer leaves out is its zero value, as a list's item's is, and one tagged required is one every entry is given. A map is one setting, given whole.
EnvOption
type EnvOption func(*envLayer)EnvOption is how a config reads the environment.
DotEnv
func DotEnv(files ...string) EnvOptionDotEnv reads these .env files for the variables the process lacks; one that does not exist is skipped.
EnvFrom
func EnvFrom(variables map[string]string) EnvOptionEnvFrom reads these variables in place of the process's, as a test gives them.
Var
func Var(path, name string) EnvOptionVar gives the setting at path a variable of its own in place of its prefixed one, such as the PORT and DATABASE_URL platforms set.
FileOption
type FileOption func(*fileLayer)FileOption is how a config reads a file.
NoSecrets
func NoSecrets() FileOptionNoSecrets refuses the config when the file gives a secret, for a file committed beside the code, whose secrets come from the environment: the error names the variable and its _FILE that give it instead, never the secret, and a missing secret's error names no such file.
Optional
func Optional() FileOptionOptional lets the file be absent: then it declares nothing, and Explain says so.
Given
type Given struct {
Value string
From Origin
}Given is a value a setting was given, as JSON, a span spelled, a secret *** and none unset, and where it came from.
Line
type Line struct {
Path, Value, From, Over string
// Given is every value the setting was given, newest first: its own, then
// the ones it went over; From is Given[0].From.String(). It is empty from
// a server before 0.1.1.
Given []Given
}Line is a setting's line of Explain: its value as JSON, a span spelled, a secret *** and none unset, the layer that gave it and the values it went over, newest first.
Line.String
func (l Line) String() stringOrigin
type Origin struct {
Kind OriginKind
Place int // a layer's place in the list, the declaration 1
Path string // a file's path
Variable string // an env's variable
DotEnv string // the .env file that set the variable
File string // the file a NAME_FILE variable named
Version int64 // a change's version
At time.Time // when a change was made
}Origin is where a value came from: its kind, and only the fields that kind names, the others zero. Its String is the text a Line's From says: the declaration, layer 2, app.yaml, APP_PORT in .env, or a change, version 7, 2026-10-13 14:03:05 UTC. A kind from a newer server is kept as it was sent, and its String is the kind.
Origin.String
func (o Origin) String() stringString is the text a Line's From says, as the core writes it.
OriginKind
type OriginKind stringOriginKind is what gave a value.
OriginDeclaration
const (
OriginDeclaration OriginKind = "declaration"
OriginLayer OriginKind = "layer" // an object in a Bun or Python program's list of layers
OriginFile OriginKind = "file"
OriginEnv OriginKind = "env"
OriginChange OriginKind = "change"
)The kinds an origin has.
Secret
type Secret struct {
// contains filtered or unexported fields
}Secret is a setting's text that prints as *** wherever it goes: fmt, JSON, slog and errors. Reveal gives the text, where the program hands it to what needs it. Hiding it from print is not access control, which the server's tokens are.
NewSecret
func NewSecret(text string) SecretNewSecret is a secret of this text, a declaration's default.
Secret.Format
func (Secret) Format(f fmt.State, _ rune)Secret.GoString
func (Secret) GoString() stringSecret.LogValue
func (Secret) LogValue() slog.ValueSecret.MarshalJSON
func (Secret) MarshalJSON() ([]byte, error)Secret.MarshalText
func (Secret) MarshalText() ([]byte, error)Secret.Reveal
func (s Secret) Reveal() stringReveal is the secret's text.
Secret.String
func (Secret) String() stringSecret.UnmarshalJSON
func (s *Secret) UnmarshalJSON(text []byte) errorUpdateOption
type UpdateOption func(*int64)UpdateOption is what an update needs of the config.
IfVersion
func IfVersion(version int64) UpdateOptionIfVersion keeps the change only while the config is at this version: ErrConflict when another change came since, so that an admin page does not overwrite a change it never showed.