...

Package envconfig

import "github.com/kelseyhightower/envconfig"
Overview
Index

Overview ▾

Package envconfig implements decoding of environment variables based on a user defined specification. A typical use is using environment variables for configuration settings.

Constants

const (
    // DefaultListFormat constant to use to display usage in a list format
    DefaultListFormat = `This application is configured via the environment. The following environment
variables can be used:
{{range .}}
{{usage_key .}}
  [description] {{usage_description .}}
  [type]        {{usage_type .}}
  [default]     {{usage_default .}}
  [required]    {{usage_required .}}{{end}}
`
    // DefaultTableFormat constant to use to display usage in a tabular format
    DefaultTableFormat = `This application is configured via the environment. The following environment
variables can be used:

KEY	TYPE	DEFAULT	REQUIRED	DESCRIPTION
{{range .}}{{usage_key .}}	{{usage_type .}}	{{usage_default .}}	{{usage_required .}}	{{usage_description .}}
{{end}}`
)

Variables

ErrInvalidSpecification indicates that a specification is of the wrong type.

var ErrInvalidSpecification = errors.New("specification must be a struct pointer")

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 Usage

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

Usage writes usage information to stdout using the default header and table format

func Usagef

func Usagef(prefix string, spec interface{}, out io.Writer, format string) error

Usagef writes usage information to the specified io.Writer using the specifed template specification

func Usaget

func Usaget(prefix string, spec interface{}, out io.Writer, tmpl *template.Template) error

Usaget writes usage information to the specified io.Writer using the specified template

type Decoder

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

type Decoder interface {
    Decode(value string) error
}

type ParseError

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

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

func (*ParseError) Error

func (e *ParseError) Error() string

type Setter

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

type Setter interface {
    Set(value string) error
}