Help us shape the future of Go! Take the 2026 Go Developer Survey

envconfig

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	EnvironmentReader = ReaderFunc(func(key string) (string, bool, error) {
		v, ok := os.LookupEnv(key)
		return v, ok, nil
	})
)
View Source
var ErrInvalidSpecification = errors.New("specification must be a struct pointer")

ErrInvalidSpecification indicates that a specification is of the wrong type.

Functions

func CheckDisallowed

func CheckDisallowed(prefix string, spec interface{}) error

CheckDisallowed checks that no environment variables with the prefix are set that we don't know how or want to parse. This is likely only meaningful with a non-empty prefix.

func MustProcess

func MustProcess(prefix string, spec interface{})

MustProcess is the same as Process but panics if an error occurs

func Process

func Process(prefix string, spec interface{}) error

Process populates the specified struct based on environment variables

func ProcessWithReader added in v1.0.0

func ProcessWithReader(prefix string, spec interface{}, reader Reader) error

Types

type Decoder

type Decoder interface {
	Decode(value string) error
}

Decoder has the same semantics as Setter, but takes higher precedence. It is provided for historical compatibility.

type ParseError

type ParseError struct {
	KeyName   string
	FieldName string
	TypeName  string
	Value     string
	Err       error
}

A ParseError occurs when an environment variable cannot be converted to the type required by a struct field during assignment.

func (*ParseError) Error

func (e *ParseError) Error() string

type Reader added in v1.0.0

type Reader interface {
	Read(string) (string, bool, error)
}

type ReaderFunc added in v1.0.0

type ReaderFunc func(string) (string, bool, error)

func (ReaderFunc) Read added in v1.0.0

func (f ReaderFunc) Read(key string) (string, bool, error)

type Setter

type Setter interface {
	Set(value string) error
}

Setter is implemented by types can self-deserialize values. Any type that implements flag.Value also implements Setter.

Jump to

Keyboard shortcuts

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