Documentation
¶
Overview ¶
Package config populates struct fields from registered configuration sources.
Use this package when you need to load configuration values into a struct from external sources such as environment variables. Fields are marked for processing using struct tags that specify the source type and optional default values.
The package includes a built-in environment variable source that maps struct field names to SNAKE_CASE environment variable names. Custom sources can be registered to support additional configuration backends.
Processed configurations can optionally be validated to ensure all required values are present and conform to expected constraints.
Index ¶
Constants ¶
const ( // ProcessorTag specifies which configuration processor should populate the struct field. ProcessorTag = "config" // DefaultTag supplies a fallback value when a processor does not return a value for the field. DefaultTag = "config_default" )
const (
// ProcessorTypeEnv identifies the environment variable processor.
ProcessorTypeEnv = "ENV"
)
Variables ¶
This section is empty.
Functions ¶
func MustRegisterProcessor ¶
func MustRegisterProcessor(name string, fn SourceFunc)
MustRegisterProcessor registers a SourceFunc for a given processor name.
func Process ¶
Process sets struct field values using registered configuration sources. A field is processed only when it specifies the `config` tag with a source type. If the source returns no value and a default is not provided via the `config_default` tag, an error is returned.
func ProcessAndValidate ¶
ProcessAndValidate processes configuration and validates the resulting struct.
Types ¶
type SourceFunc ¶
SourceFunc fetches a configuration value for a field. It should return the value and whether it was found.