Documentation
¶
Overview ¶
Package config provides the small reflection-free runtime used by generated Spice configuration binders.
Index ¶
- func Decode[T any](ctx context.Context, snapshot Snapshot, decoder Decoder[T], ...) (T, error)
- type Decoder
- type Entry
- type EnvironmentSource
- type JSONOptions
- type JSONSource
- type Kind
- type LookupEnv
- type MapSource
- type Options
- type Origin
- type Property
- type Request
- type Schema
- type Snapshot
- func (s Snapshot) Boolean(key string) (bool, error)
- func (s Snapshot) Duration(key string) (time.Duration, error)
- func (s Snapshot) Entry(key string) (Entry, bool)
- func (s Snapshot) Integer(key string) (int64, error)
- func (s Snapshot) Keys() []string
- func (s Snapshot) Lookup(key string) (string, bool)
- func (s Snapshot) Redacted() map[string]string
- func (s Snapshot) RequiredString(key string) (string, error)
- func (s Snapshot) String() string
- type Source
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type EnvironmentSource ¶
type EnvironmentSource struct {
// contains filtered or unexported fields
}
EnvironmentSource reads only schema-declared environment variables.
func NewEnvironmentSource ¶
func NewEnvironmentSource( name string, prefix string, lookup LookupEnv, ) (EnvironmentSource, error)
NewEnvironmentSource creates an explicit environment source. prefix must be empty or a portable uppercase environment prefix.
func OSEnvironment ¶
func OSEnvironment(prefix string) (EnvironmentSource, error)
OSEnvironment creates a source backed by os.LookupEnv.
func (EnvironmentSource) Load ¶
Load checks only schema-derived or explicitly named environment variables.
func (EnvironmentSource) Name ¶
func (s EnvironmentSource) Name() string
Name returns the source identity used in provenance.
type JSONOptions ¶
type JSONOptions struct {
// Required makes the base <name>.json file mandatory. Profile files remain
// optional because deployment profiles commonly share one artifact.
Required bool
// MaxBytes bounds each individual file. Zero uses 1 MiB.
MaxBytes int64
}
JSONOptions controls a rooted JSON file source.
type JSONSource ¶
type JSONSource struct {
// contains filtered or unexported fields
}
JSONSource loads one base object and ordered active-profile objects from a rooted directory.
func NewJSONSource ¶
func NewJSONSource( name string, directory string, baseName string, options JSONOptions, ) (JSONSource, error)
NewJSONSource validates a rooted JSON source. baseName is a portable filename stem, not a relative path.
func (JSONSource) Name ¶
func (s JSONSource) Name() string
Name returns the source identity used in provenance.
type Kind ¶
type Kind string
Kind identifies one generated property's scalar representation.
const ( // KindString identifies a string property. KindString Kind = "string" // KindBoolean identifies a Boolean property accepted by conversion.Boolean. KindBoolean Kind = "boolean" // KindInteger identifies a base-10 signed 64-bit integer property. KindInteger Kind = "integer" // KindDuration identifies a conversion.Duration property. KindDuration Kind = "duration" )
type MapSource ¶
type MapSource struct {
// contains filtered or unexported fields
}
MapSource is an immutable in-memory source useful for explicit overrides and tests.
func NewMapSource ¶
NewMapSource copies values into a named source.
type Property ¶
type Property struct {
Key string
Kind Kind
Description string
Module string
Environment string
Default string
HasDefault bool
Required bool
Secret bool
}
Property is generated metadata for one exact configuration key.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request is the immutable source-load request.
func (Request) Properties ¶
Properties returns the generated schema in key order.
type Schema ¶
type Schema struct {
// contains filtered or unexported fields
}
Schema is immutable-by-construction generated configuration metadata.
func MustSchema ¶
MustSchema returns a validated schema or panics for invalid package-owned generated metadata.
func (Schema) Properties ¶
Properties returns property metadata in key order.
type Snapshot ¶
type Snapshot struct {
// contains filtered or unexported fields
}
Snapshot is one immutable-by-construction resolved configuration view.
func Resolve ¶
func Resolve( ctx context.Context, schema Schema, options Options, sources ...Source, ) (Snapshot, error)
Resolve merges defaults and sources from lowest to highest precedence, validates required/known/scalar properties, and preserves winning origins.
func (Snapshot) Boolean ¶
Boolean decodes one required Boolean without including its raw value in an error, which keeps secret values out of diagnostics.
func (Snapshot) Lookup ¶
Lookup returns one raw value. Generated binders use this for optional string and custom scalar decoding.
func (Snapshot) Redacted ¶
Redacted returns a complete key/value copy safe for logs and diagnostics.
func (Snapshot) RequiredString ¶
RequiredString returns one required raw string.