config

package
v0.23.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package config provides explicit, typed environment configuration without reflection. A Reader accumulates all configuration errors for one useful startup failure instead of panicking at the first missing value.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FieldError added in v0.23.0

type FieldError struct {
	Key  string
	Rule string
}

FieldError identifies an invalid configuration field without retaining its supplied value or the value-bearing conversion error. Key is the name passed by application code, not an untrusted field name read from a configuration file. Rule is one of required, integer, boolean, or duration for Reader errors. Errors accumulated by Reader remain discoverable with errors.As.

func (*FieldError) Error added in v0.23.0

func (problem *FieldError) Error() string

type Reader

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

Reader holds a snapshot of configuration and accumulates typed conversion errors. Construct a Reader with FromEnvironment or FromMap before loading files.

func FromEnvironment

func FromEnvironment() *Reader

func FromMap

func FromMap(values map[string]string) *Reader

FromMap copies values so later caller changes do not affect configuration.

func (*Reader) Bool

func (reader *Reader) Bool(key string, fallback bool) bool

func (*Reader) Duration

func (reader *Reader) Duration(key string, fallback time.Duration) time.Duration

func (*Reader) Err

func (reader *Reader) Err() error

Err returns all errors accumulated by Required, Int, Bool, and Duration.

func (*Reader) Int

func (reader *Reader) Int(key string, fallback int) int

func (*Reader) LoadFile

func (reader *Reader) LoadFile(path string) error

LoadFile loads KEY=VALUE pairs as defaults; existing reader values win. Matching outer quotes are stripped, without escape expansion or interpolation. A missing optional development file is ignored.

func (*Reader) Required

func (reader *Reader) Required(key string) string

func (*Reader) String

func (reader *Reader) String(key, fallback string) string

Jump to

Keyboard shortcuts

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