config

package
v1.0.36 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 6 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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_").

func (Environment) Lookup

func (source Environment) Lookup(key string) (string, bool)

Lookup implements Source.

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

func New(sources ...Source) (Loader, error)

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

func (loader Loader) Bool(key string, fallback bool) (bool, error)

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

func (loader Loader) Duration(key string, fallback time.Duration) (time.Duration, error)

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

func (loader Loader) Enum(key, fallback string, values ...string) (string, error)

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

func (loader Loader) Int(key string, fallback, min, max int) (int, error)

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

func (loader Loader) RequiredInt(key string, min, max int) (int, error)

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

func (loader Loader) RequiredString(key string) (string, error)

RequiredString returns a non-empty, whitespace-trimmed setting.

func (Loader) String

func (loader Loader) String(key, fallback string) (string, error)

String returns key or fallback when no source defines it.

type Map

type Map struct {
	// contains filtered or unexported fields
}

Map is an immutable copy of one caller-owned settings map.

func NewMap

func NewMap(values map[string]string) Map

NewMap copies values so later mutations by the caller cannot change a Loader's effective configuration.

func (Map) Lookup

func (source Map) Lookup(key string) (string, bool)

Lookup implements Source.

type Source

type Source interface {
	Lookup(key string) (string, bool)
}

Source looks up one named setting. A Source must be safe for concurrent use. Higher-priority sources appear first when constructing a Loader.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL