Documentation
¶
Overview ¶
Package config provides explicit, layered configuration lookup for host applications. It intentionally does not install process-wide settings or make library constructors read environment variables implicitly.
Index ¶
- Variables
- type Environment
- type Loader
- func (loader Loader) Bool(key string, fallback bool) (bool, error)
- func (loader Loader) Duration(key string, fallback time.Duration) (time.Duration, error)
- func (loader Loader) Enum(key, fallback string, values ...string) (string, error)
- func (loader Loader) Int(key string, fallback, min, max int) (int, error)
- func (loader Loader) RequiredInt(key string, min, max int) (int, error)
- func (loader Loader) RequiredString(key string) (string, error)
- func (loader Loader) String(key, fallback string) (string, error)
- type Map
- type Source
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidSource reports a nil or unusable configuration source. ErrInvalidSource = errors.New("crdt config: invalid source") // ErrInvalidKey reports a key outside the portable upper-snake-case form. ErrInvalidKey = errors.New("crdt config: invalid key") // ErrRequired reports an absent or empty required setting. ErrRequired = errors.New("crdt config: required value is missing") // ErrInvalidValue reports an invalid or out-of-range setting. Error text // deliberately contains its key but never the setting value. ErrInvalidValue = errors.New("crdt config: invalid value") )
Functions ¶
This section is empty.
Types ¶
type Environment ¶
type Environment struct {
// contains filtered or unexported fields
}
Environment is an environment-variable Source. Prefix is prepended to every lookup key, allowing one process to host multiple independent apps.
func NewEnvironment ¶
func NewEnvironment(prefix string) (Environment, error)
NewEnvironment creates a portable environment source. Prefix may be empty or use the same upper-snake-case form as a key, including a trailing underscore (for example, "CRDT_").
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader resolves settings from an ordered, immutable source list. It is safe for concurrent lookups when its Sources are safe for concurrent use.
func New ¶
New creates a Loader. The first source that contains a key wins, so a typical application passes explicit deployment values before Environment and compiled defaults.
func (Loader) Bool ¶
Bool parses a strictly formatted Boolean setting or returns fallback when the setting is absent. Accepted values are those accepted by strconv.ParseBool.
func (Loader) Duration ¶
Duration parses a positive duration setting or returns fallback when absent. The fallback must also be positive so zero can never silently disable a timeout in host transport configuration.
func (Loader) Enum ¶
Enum returns a configured value only when it is one of values. The fallback and accepted values are validated first so an absent setting cannot mask a programmer configuration error.
func (Loader) Int ¶
Int parses a setting in the inclusive range [min, max], or returns fallback when absent. Supplying min greater than max is a programmer configuration error and is rejected even when key is absent.
func (Loader) RequiredInt ¶
RequiredInt parses a required integer in the inclusive range [min, max]. It rejects an invalid range before reading sources and never includes the configured value in an error.
func (Loader) RequiredString ¶
RequiredString returns a non-empty, whitespace-trimmed setting.