Documentation
¶
Overview ¶
Package config loads typed application configuration from explicit sources. New applications should use Loader to avoid process-global mutation and must obtain production secrets from an appropriate secret manager.
Index ¶
- func Bind(target any, filepath ...string) error
- func Env(key string, defaultValue ...string) string
- func Get(key string, defaultValue ...string) string
- func GetBool(key string, defaultValue ...bool) bool
- func GetDuration(key string, defaultValue ...time.Duration) time.Duration
- func GetInt(key string, defaultValue ...int) int
- func GetString(key string, defaultValue ...string) string
- func IntRange(field string, value, minimum, maximum int64) error
- func Load(filepath ...string) error
- func LoadAndUnmarshal(target any, filepath ...string) error
- func LoadStruct[T any](filepath ...string) (*T, error)
- func LoadValue[T any](loader *Loader, normalize func(*T) error, validate func(T) error) (T, error)
- func MaskSecret(secret string) string
- func MustLoad[T any](filepath ...string) *T
- func OneOf(field, value string, allowed ...string) error
- func Port(field string, value int) error
- func Required(field, value string) error
- func StringLength(field, value string, minimum, maximum int) error
- func Unmarshal(v any) error
- type Loader
- type LoaderOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetDuration ¶
GetDuration retrieves a time.Duration config value (e.g. "10s", "5m").
func LoadAndUnmarshal ¶
LoadAndUnmarshal parses a .env file and unmarshals environment variables into the target struct pointer.
func LoadStruct ¶
LoadStruct parses a .env file and populates a new struct pointer of type T.
func LoadValue ¶
LoadValue returns a populated value only after normalization and validation succeed, avoiding exposure of partially loaded configuration.
func MaskSecret ¶
MaskSecret redacts sensitive credentials (e.g. passwords, AWS keys) for logging safety.
func MustLoad ¶
MustLoad parses a .env file and populates a new struct of type T, panicking on unmarshal failure.
func StringLength ¶
StringLength validates a configuration string using Unicode code-point length.
Types ¶
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader is an immutable, process-environment-independent configuration source.
func NewLoader ¶
func NewLoader(options LoaderOptions) (*Loader, error)
NewLoader constructs an immutable loader; environment values override dotenv values.