envconfig

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

README

envconfig

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

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

func Mask

func Mask(v any) string

Mask returns a string representation of any struct, masking fields tagged as sensitive:"true".

Types

type Unmarshaler

type Unmarshaler interface {
	UnmarshalEnv(value string) error
}

Unmarshaler is the interface implemented by types that can parse themselves from a raw environment variable string.

UnmarshalEnv receives the raw string value (never empty) and is responsible for populating the receiver. Return a descriptive error if the value is invalid.

Example:

type LogLevel struct{ level string }

func (l *LogLevel) UnmarshalEnv(value string) error {
    switch value {
    case "DEBUG", "INFO", "WARN", "ERROR":
        l.level = value
        return nil
    default:
        return fmt.Errorf("invalid log level %q, must be one of DEBUG, INFO, WARN, ERROR", value)
    }
}

Jump to

Keyboard shortcuts

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