Documentation
¶
Overview ¶
Package conflata loads configuration structs by reading environment variables first and falling back to external secret providers such as AWS Secrets Manager, HashiCorp Vault, or Google Secret Manager. Fields are annotated with `conflata` struct tags that describe which env/providor keys to read, and the loader reports grouped errors so callers can decide how to handle missing values.
Example:
type Config struct {
DatabaseURL string `conflata:"env:DATABASE_URL provider:prod/database-url"`
}
loader := conflata.New(conflata.WithProvider("aws", awsProvider))
if err := loader.Load(ctx, &cfg); err != nil {
if group, ok := err.(*conflata.ErrorGroup); ok {
log.Println(group)
} else {
log.Fatal(err)
}
}
Index ¶
- type AttemptError
- type DecodeFunc
- type EnvLookupFunc
- type ErrorGroup
- type FieldError
- type Loader
- type Option
- func WithDecoder(name string, fn DecodeFunc) Option
- func WithDefaultFormat(name string) Option
- func WithDefaultProvider(name string) Option
- func WithEnvLookup(fn EnvLookupFunc) Option
- func WithProvider(name string, provider Provider) Option
- func WithProviderPrefix(fn func() string) Option
- func WithProviderSuffix(fn func() string) Option
- type Provider
- type ValueSource
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AttemptError ¶
type AttemptError struct {
Source ValueSource
Identifier string
Err error
}
AttemptError captures metadata about a failed attempt (environment lookup, provider fetch, decode) that occurred while resolving a single field.
func (AttemptError) Error ¶
func (a AttemptError) Error() string
Error implements the error interface.
type EnvLookupFunc ¶
EnvLookupFunc describes how to look up environment variables. Override with WithEnvLookup when running in custom environments.
type ErrorGroup ¶
type ErrorGroup struct {
// contains filtered or unexported fields
}
ErrorGroup groups field errors discovered during a loader run. The group can be inspected to understand which fields failed and why.
func (*ErrorGroup) Error ¶
func (g *ErrorGroup) Error() string
Error implements the error interface.
func (*ErrorGroup) Fields ¶
func (g *ErrorGroup) Fields() []FieldError
Fields returns a copy of the underlying FieldError slice for inspection.
func (*ErrorGroup) Has ¶
func (g *ErrorGroup) Has() bool
Has reports whether the group contains any field errors.
type FieldError ¶
type FieldError struct {
FieldPath string
Attempts []AttemptError
}
FieldError aggregates all failed attempts for a field. When a field cannot be satisfied it may record multiple AttemptErrors that callers can inspect to decide how to handle the failure.
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader populates configuration structs from environment variables and external providers according to the struct tags.
type Option ¶
type Option func(*Loader)
Option configures the Loader.
func WithDecoder ¶
func WithDecoder(name string, fn DecodeFunc) Option
WithDecoder registers a custom format decoder keyed by name. Struct tags can then reference the decoder via `format:decoder`.
func WithDefaultFormat ¶
WithDefaultFormat overrides the default decoder used for structured types when no per-field format is provided.
func WithDefaultProvider ¶
WithDefaultProvider picks which registered provider should be used when a tag does not specify a backend explicitly.
func WithEnvLookup ¶
func WithEnvLookup(fn EnvLookupFunc) Option
WithEnvLookup overrides the environment variable lookup strategy.
func WithProvider ¶
WithProvider registers a provider under the supplied name so struct tags can reference it via the `backend:` key.
func WithProviderPrefix ¶ added in v1.1.0
WithProviderPrefix supplies a function whose result is prepended to provider keys prior to lookup (for example to inject environment names).
func WithProviderSuffix ¶ added in v1.1.0
WithProviderSuffix supplies a function whose result is appended to provider keys prior to lookup.
type Provider ¶
Provider fetches configuration values from an external system such as Vault, AWS Secrets Manager, or GCP Secret Manager. Custom providers can be registered with WithProvider.
type ValueSource ¶
type ValueSource string
ValueSource identifies where a configuration value was attempted to be read from (environment, provider, decoder, tag parsing, etc.).
const ( SourceEnv ValueSource = "env" SourceProvider ValueSource = "provider" SourceDecoder ValueSource = "decoder" SourceTag ValueSource = "tag" )