Documentation
¶
Overview ¶
Package cfg is the typed vocabulary a Go library uses to declare its configuration. Each wrapper carries the decoded value alongside its schema info (description, default, validation) for one field. Only wrappers in this package satisfy the Value constraint, so a library author cannot place a bare Go type as the element of a List, Map, or Set.
Index ¶
- func Decode(ct *ConfigurationType, raw map[string]any) (any, error)
- func ValidateConfigurationType(ct *ConfigurationType) error
- type Any
- type Boolean
- type ConfigurationType
- type Integer
- type List
- type Map
- type Null
- type Number
- type Object
- type Set
- type String
- type Validator
- type ValidatorDesc
- type Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
func Decode(ct *ConfigurationType, raw map[string]any) (any, error)
Decode populates a fresh instance returned by ct.New() with values from raw. Field names match in kebab form (AssumeRole reads from "assume-role"). A non-pointer wrapper field is required; a pointer to a wrapper is optional and falls back to the wrapper's Default when the key is absent. An unknown key in raw is an error.
This first cut supports atomic wrappers (String, Integer, Number, Boolean) and nested struct recursion. Collection and Object wrappers are not yet handled.
func ValidateConfigurationType ¶
func ValidateConfigurationType(ct *ConfigurationType) error
ValidateConfigurationType verifies that every reachable field in a fresh New() instance is a wrapper from this package or a struct whose fields recurse to wrappers. Call this from a library's unit tests to catch misuse at go-test time. The runtime calls it at library load to fail fast on a misdeclared configuration.
Types ¶
type ConfigurationType ¶
ConfigurationType registers a library's configuration. New returns a pointer to a fresh configuration struct. The decoder populates its fields from the operator's config.ub. The struct's fields must be wrapper types from this package or nested structs whose fields are wrapper types; the schema walker rejects any other field type at library load. Description appears in the schema commands.
type List ¶
Element supplies the schema info (description, default, validator) applied to each item. Its own Value is ignored.
type Object ¶
Object wraps a user struct in a position that requires a Value, such as the element type of a List or Map. T must be a struct whose fields are wrapper types or nested structs; the schema walker rejects any other field type at library load. An optional nested struct at the top level of a Configuration uses a plain *Struct and does not need this wrapper.
type Set ¶
Set is backed by a slice rather than a map so element types need not be comparable; the decoder rejects duplicates.
type Validator ¶
type Validator interface {
Check(any) error
Describe() ValidatorDesc
}
Validator runs after decode to check that a value meets a library author's constraints. Describe returns a structured form so the schema commands and editor tooling can render the constraint declaratively rather than as an opaque function.
type ValidatorDesc ¶
ValidatorDesc names a validator's kind and parameters. Standard kinds include "pattern", "range", "length", "enum", "all", and "custom"; introspection tools render the known kinds to their UB modifier and fall back to the description text for "custom".