Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoValidProvider indicates that no suitable provider could be found after attempting all available options. ErrNoValidProvider = errors.New("no valid provider found") // ErrNotMatched indicates that a specific condition for selecting a provider was not met. ErrNotMatched = errors.New("provider not matched") // ErrNilProvider indicates that a case returned a nil Provider without an error. ErrNilProvider = errors.New("provider is nil") )
Functions ¶
Types ¶
type ExpandEnv ¶
type ExpandEnv struct {
// contains filtered or unexported fields
}
ExpandEnv is a Provider adapter that expands environment variables present in the underlying provider's raw configuration bytes.
It treats the configuration as UTF-8 text and replaces $var or ${var} using os.ExpandEnv rules. Undefined variables expand to an empty string. This is useful when your config file or HTTP payload includes placeholders like "${PORT}" that should be resolved at runtime.
Note: This adapter is text-oriented. If the underlying data is non-text or contains many literal '$' characters, expansion may be undesirable.
func NewExpandEnv ¶
NewExpandEnv wraps an existing Provider and returns a new Provider that expands environment variable placeholders in the returned bytes.
type Provider ¶
type Provider interface {
// Read returns the entire configuration as raw []bytes to be parsed.
// The provided context controls cancellation and deadlines.
Read(ctx context.Context) ([]byte, error)
}
Provider represents a configuration provider. Providers can read configuration from a source (file, HTTP, etc.)
func Selector ¶ added in v0.0.3
Selector tries each case function in order with the given parameter. It returns the first Provider that does not return an error. If all cases return an error, it returns an error indicating no valid provider was found.
func SelectorWithErrors ¶ added in v0.0.3
SelectorWithErrors behaves like Selector but aggregates non-matching errors (excluding ErrNotMatched) and returns them joined with ErrNoValidProvider when no provider is selected. Callers can use errors.Is to test for ErrNoValidProvider while still getting detailed context for debugging.
type ReaderFunc ¶ added in v0.0.4
type Select ¶ added in v0.0.4
type Select[T any] struct { // contains filtered or unexported fields }
Select is a helper struct to hold the parameter and case functions for Selector.