config

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package config decodes environment-backed settings into typed Go structs.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode[T any](lookup LookupFunc) (T, error)

Decode decodes lookup values into a typed configuration struct.

func Load

func Load[T any](opts ...Option) (T, error)

Load loads environment files and decodes the merged values into a typed struct.

Types

type Error

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

Error reports one or more configuration problems.

func (*Error) Error

func (e *Error) Error() string

Error returns a human-readable summary of the configuration problems.

func (*Error) Problems

func (e *Error) Problems() []Problem

Problems returns a copy of the configuration problems.

type LookupFunc

type LookupFunc func(string) (string, bool)

LookupFunc looks up a configuration value by key.

func FromMap

func FromMap(values map[string]string) LookupFunc

FromMap returns a lookup function backed by values.

type Option

type Option func(*options)

Option configures Load.

func WithDir

func WithDir(dir string) Option

WithDir configures the directory used for environment files.

func WithEnvironment

func WithEnvironment(environment string) Option

WithEnvironment configures the environment-specific file suffix.

func WithFiles

func WithFiles(files ...string) Option

WithFiles configures the exact environment files Load should read.

func WithLookup

func WithLookup(lookup LookupFunc) Option

WithLookup configures the highest-priority lookup source.

func WithoutEnvFiles

func WithoutEnvFiles() Option

WithoutEnvFiles disables environment file loading.

type Problem

type Problem struct {
	// Field is the exported struct field name, when the problem is tied to a field.
	Field string
	// Key is the environment lookup key used for the field.
	Key string
	// Message explains the validation or parsing failure.
	Message string
}

Problem describes one invalid or missing configuration value.

func (Problem) String

func (p Problem) String() string

String returns a stable, human-readable problem description.

type Secret

type Secret string

Secret stores a sensitive configuration value and redacts itself in logs.

Example
secret := Secret("postgres://localhost/ohm")

fmt.Println(secret)
fmt.Println(secret.Reveal())
Output:
[REDACTED]
postgres://localhost/ohm

func (Secret) LogValue

func (s Secret) LogValue() slog.Value

LogValue returns a redacted slog value.

func (Secret) MarshalJSON

func (s Secret) MarshalJSON() ([]byte, error)

MarshalJSON returns a redacted JSON string.

func (Secret) Reveal

func (s Secret) Reveal() string

Reveal returns the underlying sensitive value.

func (Secret) String

func (s Secret) String() string

String returns a redacted display value.

func (*Secret) UnmarshalText

func (s *Secret) UnmarshalText(text []byte) error

UnmarshalText stores text as a secret value.

Jump to

Keyboard shortcuts

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