env

package
v0.0.0-...-3f4b425 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// use a specified env var instead of one derived from struct field name
	A_ALIAS = "alias"
	// default value is used if env var is not specified
	A_DEFAULT = "default"
	// an error is returned if a required field has no associated env var
	A_REQUIRE = "require"
	// do not set the named field from any env var
	A_IGNORE = "ignore"
)

Tag atttributes to specify how to handle env vars

Variables

View Source
var (
	ErrNeedPrefix = errors.New("a prefix must be provided")
	ErrBadSpec    = errors.New("specification must be a struct pointer")
)

returned errs

Functions

func Load

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

Process populates the specified struct based on environment variables. Environment variables should be all CAPITAL LETTERS of the form:

ToUpper({prefix}_{envvarident})

Types

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 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