config

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package config loads environment variables into typed application configuration. It uses reflection for configuration decoding, independently of build-time DI.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnvironmentValues

func EnvironmentValues(env pfw.Environment, dir string) (map[string]string, error)

EnvironmentValues reads optional layered files without changing process state. Reserved PFW_ENV/PFW_ENV_DIR selectors are never supplied by dotenv files.

func Invalid

func Invalid(field, reason string) error

Invalid creates a validation error without requiring an environment key.

func Load

func Load[T any](options Options) (T, error)

Load returns a fully parsed and validated struct, or its zero value on error. Defaults apply only to missing keys: present empty values never use defaults.

Types

type EnvironmentValidator

type EnvironmentValidator interface{ ValidateEnvironment(pfw.Environment) error }

type Error

type Error struct{ Fields []*FieldError }

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() []error

type FieldError

type FieldError struct{ Field, Variable, Reason string }

func (*FieldError) Error

func (e *FieldError) Error() string

type Options

type Options struct {
	Prefix string
	// Lookup defaults to os.LookupEnv. Supply an isolated lookup in tests.
	Lookup func(string) (string, bool)
	// EnvFiles are read in order; later files override earlier ones. Lookup wins.
	EnvFiles []string
	// IgnoreMissingEnvFiles ignores absent files, never syntax/read errors.
	IgnoreMissingEnvFiles bool
	// Environment selects .env, .env.<name>, .env.<name>.local when EnvFiles is empty.
	Environment pfw.Environment
	EnvDir      string
}

type Validator

type Validator interface{ Validate() error }

Validator is optionally implemented by the configuration value or its pointer. Validation messages are supplied by the application and should omit secrets.

Jump to

Keyboard shortcuts

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