Documentation
¶
Overview ¶
Package config provides a unified configuration loader for OpenChoreo components.
Index ¶
- type FieldError
- func Invalid(path *Path, msg string) *FieldError
- func MustBeGreaterThan[T constraints.Ordered](path *Path, value, min T) *FieldError
- func MustBeInRange[T constraints.Ordered](path *Path, value, min, max T) *FieldError
- func MustBeLessThanOrEqual[T constraints.Ordered](path *Path, value, max T) *FieldError
- func MustBeNonNegative[T constraints.Ordered](path *Path, value T) *FieldError
- func MustBeOneOf(path *Path, value string, allowed []string) *FieldError
- func MustNotBeEmpty(path *Path, value string) *FieldError
- func Required(path *Path) *FieldError
- type Loader
- func (l *Loader) DumpYAML(w io.Writer) error
- func (l *Loader) LoadFlags(flags *pflag.FlagSet, mappings map[string]string) error
- func (l *Loader) LoadWithDefaults(defaults any, configPath string) error
- func (l *Loader) Raw() map[string]any
- func (l *Loader) Set(key string, value any) error
- func (l *Loader) Unmarshal(path string, out any) error
- func (l *Loader) UnmarshalAndValidate(path string, out any) error
- type Path
- type ValidationErrors
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FieldError ¶ added in v0.13.0
FieldError represents a validation error for a specific config field.
func Invalid ¶ added in v0.13.0
func Invalid(path *Path, msg string) *FieldError
Invalid returns a generic validation error with a custom message.
func MustBeGreaterThan ¶ added in v0.13.0
func MustBeGreaterThan[T constraints.Ordered](path *Path, value, min T) *FieldError
MustBeGreaterThan returns an error if value is not greater than min.
func MustBeInRange ¶ added in v0.13.0
func MustBeInRange[T constraints.Ordered](path *Path, value, min, max T) *FieldError
MustBeInRange returns an error if value is not within [min, max].
func MustBeLessThanOrEqual ¶ added in v0.13.0
func MustBeLessThanOrEqual[T constraints.Ordered](path *Path, value, max T) *FieldError
MustBeLessThanOrEqual returns an error if value is greater than max.
func MustBeNonNegative ¶ added in v0.13.0
func MustBeNonNegative[T constraints.Ordered](path *Path, value T) *FieldError
MustBeNonNegative returns an error if value is negative.
func MustBeOneOf ¶ added in v0.13.0
func MustBeOneOf(path *Path, value string, allowed []string) *FieldError
MustBeOneOf returns an error if value is not in the allowed list.
func MustNotBeEmpty ¶ added in v0.13.0
func MustNotBeEmpty(path *Path, value string) *FieldError
MustNotBeEmpty returns an error if the string value is empty.
func Required ¶ added in v0.13.0
func Required(path *Path) *FieldError
Required returns an error indicating a field is required.
func (*FieldError) Error ¶ added in v0.13.0
func (e *FieldError) Error() string
Error implements the error interface.
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader handles configuration loading from multiple sources.
func NewLoader ¶
NewLoader creates a new configuration loader. envPrefix should be like "OC_API" (without trailing delimiter). Environment variables use double underscore (__) for nesting: OC_API__SERVER__PORT -> server.port
func (*Loader) DumpYAML ¶ added in v0.13.0
DumpYAML writes the loaded configuration as YAML to the provided writer.
func (*Loader) LoadFlags ¶
LoadFlags applies CLI flag overrides using explicit mappings. Only flags that were explicitly set by the user are applied. Call this after LoadWithDefaults for highest priority overrides.
func (*Loader) LoadWithDefaults ¶
LoadWithDefaults loads configuration with the following priority (highest to lowest):
- Environment variables (OC_API__SERVER__PORT -> server.port)
- Config file (YAML)
- Struct defaults
If configPath is specified but the file does not exist, an error is returned. If configPath is empty, only defaults and environment variables are used.
type Path ¶ added in v0.13.0
type Path struct {
// contains filtered or unexported fields
}
Path represents a path to a config field for error reporting. It builds paths like "server.middlewares.jwt.jwks.url" for clear error messages.
type ValidationErrors ¶ added in v0.13.0
type ValidationErrors []*FieldError
ValidationErrors collects multiple validation errors.
func (ValidationErrors) Error ¶ added in v0.13.0
func (ve ValidationErrors) Error() string
Error implements the error interface, formatting all errors.
func (ValidationErrors) OrNil ¶ added in v0.13.0
func (ve ValidationErrors) OrNil() error
OrNil returns nil if there are no errors, otherwise returns the ValidationErrors.