env

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2018 License: MIT Imports: 9 Imported by: 2

README

Env

Build Status Go Report Card GolangCI GoDoc

Env provides a similar interface for environment variables as flag/pflag package.

Usage

The interface follows closely the flag/pflag packages.

package main

import "github.com/goph/env"

func main() {
	// Define environment variables using env.String(), Bool(), Int(), etc.
	var intValue *int = env.Int("int", 1234, "help message for int")
	
	// If you like, you can bind the environment variable to a variable using the Var() functions.
	var intVar int
	env.IntVar(&intVar, "int", 1234, "help message for int")
	
	// Or you can create custom variables that satisfy the Value interface (with pointer receivers)
	// and couple them to variable parsing.
	//
	// For such environment variables, the default value is just the initial value of the variable.
	var intVal env.Value
	env.Var(&intVal, "int", "help message for int")
	
	// After all variables are defined.
	env.Parse()
}

Development

When all coding and testing is done, please run the test suite:

$ make test # go test

For linting we use GolangCI.

$ make lint # golangci-lint run

You can run the whole suite with:

$ make check

License

The MIT License (MIT). Please see License File for more information.

This project is heavily inspired by flag/pflag packages.

Documentation

Overview

Package env provides a similar interface for environment variables as flag/pflag package.

The reason for this is to make configuration management in a CLI application as easy as possible. Environment variables are mostly used in server applications (eg. apps running in docker) though, so this solution is mostly beneficial for them.

Use this package along with the flag package from the stdlib or the POSIX compliant pflag (github.com/spf13/pflag) library. The general recommendation is to let flags take precedence over environment variables (when it makes sense to accept a configuration via both methods). To achieve this, make sure to parse flags after environment variables.

Here is an example for a regular application using both flags and environment variables:

package main

import (
	flag "github.com/spf13/pflag"
	"github.com/goph/env"
)

func main() {
	var debug bool

	// Flags
	listen := flag.String("listen", ":8080", "Listen on this port")
	flag.BoolVar(&debug, "debug", false, "Whether to serve extra debug information in logs")

	// Env vars
	env.BoolVar(&debug, "debug", false, "Whether to serve extra debug information in logs")

	err := env.Parse()
	if err != nil {
		panic(err)
	}

	err = flag.Parse()
	if err != nil {
		panic(err)
	}

	// ... further code
}

Index

Constants

This section is empty.

Variables

View Source
var Environment = NewEnvVarSet(ExitOnError)

Environment is the default set of environment variables, parsed from os.Environ().

Functions

func Bool

func Bool(name string, value bool, usage string) *bool

Bool defines a bool environment variable with specified name, default value, and usage string. The return value is the address of a bool variable that stores the value of the environment variable.

func BoolVar

func BoolVar(p *bool, name string, value bool, usage string)

BoolVar defines a bool environment variable with specified name, default value, and usage string. The argument p points to a bool variable in which to store the value of the environment variable.

func Duration

func Duration(name string, value time.Duration, usage string) *time.Duration

Duration defines a time.Duration environment variable with specified name, default value, and usage string. The return value is the address of a time.Duration variable that stores the value of the environment variable.

func DurationVar

func DurationVar(p *time.Duration, name string, value time.Duration, usage string)

DurationVar defines a time.Duration environment variable with specified name, default value, and usage string. The argument p points to a time.Duration variable in which to store the value of the environment variable.

func Float32

func Float32(name string, value float32, usage string) *float32

Float32 defines a float32 environment variable with specified name, default value, and usage string. The return value is the address of a float32 variable that stores the value of the environment variable.

func Float32Var

func Float32Var(p *float32, name string, value float32, usage string)

Float32Var defines a float32 environment variable with specified name, default value, and usage string. The argument p points to a float32 variable in which to store the value of the environment variable.

func Float64

func Float64(name string, value float64, usage string) *float64

Float64 defines a float64 environment variable with specified name, default value, and usage string. The return value is the address of a float64 variable that stores the value of the environment variable.

func Float64Var

func Float64Var(p *float64, name string, value float64, usage string)

Float64Var defines a float64 environment variable with specified name, default value, and usage string. The argument p points to a float64 variable in which to store the value of the environment variable.

func Int

func Int(name string, value int, usage string) *int

Int defines an int environment variable with specified name, default value, and usage string. The return value is the address of an int variable that stores the value of the environment variable.

func Int16

func Int16(name string, value int16, usage string) *int16

Int16 defines an int16 environment variable with specified name, default value, and usage string. The return value is the address of an int16 variable that stores the value of the environment variable.

func Int16Var

func Int16Var(p *int16, name string, value int16, usage string)

Int16Var defines an int16 environment variable with specified name, default value, and usage string. The argument p points to an int16 variable in which to store the value of the environment variable.

func Int32

func Int32(name string, value int32, usage string) *int32

Int32 defines an int32 environment variable with specified name, default value, and usage string. The return value is the address of an int32 variable that stores the value of the environment variable.

func Int32Var

func Int32Var(p *int32, name string, value int32, usage string)

Int32Var defines an int32 environment variable with specified name, default value, and usage string. The argument p points to an int32 variable in which to store the value of the environment variable.

func Int64

func Int64(name string, value int64, usage string) *int64

Int64 defines an int64 environment variable with specified name, default value, and usage string. The return value is the address of an int64 variable that stores the value of the environment variable.

func Int64Var

func Int64Var(p *int64, name string, value int64, usage string)

Int64Var defines an int64 environment variable with specified name, default value, and usage string. The argument p points to an int64 variable in which to store the value of the environment variable.

func Int8

func Int8(name string, value int8, usage string) *int8

Int8 defines an int8 environment variable with specified name, default value, and usage string. The return value is the address of an int8 variable that stores the value of the environment variable.

func Int8Var

func Int8Var(p *int8, name string, value int8, usage string)

Int8Var defines an int8 environment variable with specified name, default value, and usage string. The argument p points to an int8 variable in which to store the value of the environment variable.

func IntVar

func IntVar(p *int, name string, value int, usage string)

IntVar defines an int environment variable with specified name, default value, and usage string. The argument p points to an int variable in which to store the value of the environment variable.

func Parse

func Parse()

Parse parses environment variables from os.Environ() according to the definitions in the EnvVarSet. Must be called after all variables in the EnvVarSet are defined and before variables are accessed by the program.

func Parsed

func Parsed() bool

Parsed returns true if the environment variables have been parsed.

func PrintDefaults added in v0.5.0

func PrintDefaults()

PrintDefaults prints to standard error the default values of all defined environment variables.

func QueryString added in v0.5.0

func QueryString(name string, value map[string]string, usage string) *map[string]string

QueryString defines a query string environment variable with specified name, default value, and usage string. The return value is the address of a query string (string map) variable that stores the value of the environment variable.

func QueryStringVar added in v0.5.0

func QueryStringVar(p *map[string]string, name string, value map[string]string, usage string)

QueryStringVar defines a query string environment variable with specified name, default value, and usage string. The argument p points to a query string (string map) variable in which to store the value of the environment variable.

func String

func String(name string, value string, usage string) *string

String defines a string environment variable with specified name, default value, and usage string. The return value is the address of a string variable that stores the value of the environment variable.

func StringSlice added in v0.6.0

func StringSlice(name string, value []string, usage string) *[]string

StringSlice defines a string environment variable with specified name, default value, and usage string. The return value is the address of a []string variable that stores the value of the environment variable. For example:

STRING_SLICE="v1,v2"

will result in

[]string{"v1", "v2"}

func StringSliceVar added in v0.6.0

func StringSliceVar(p *[]string, name string, value []string, usage string)

StringSliceVar defines a string environment variable with specified name, default value, and usage string. The argument p points to a []string variable in which to store the value of the environment variable. For example:

STRING_SLICE="v1,v2"

will result in

[]string{"v1", "v2"}

func StringVar

func StringVar(p *string, name string, value string, usage string)

StringVar defines a string environment variable with specified name, default value, and usage string. The argument p points to a string variable in which to store the value of the environment variable.

func Uint

func Uint(name string, value uint, usage string) *uint

Uint defines a uint environment variable with specified name, default value, and usage string. The return value is the address of a uint variable that stores the value of the environment variable.

func Uint16

func Uint16(name string, value uint16, usage string) *uint16

Uint16 defines a uint16 environment variable with specified name, default value, and usage string. The return value is the address of a uint16 variable that stores the value of the environment variable.

func Uint16Var

func Uint16Var(p *uint16, name string, value uint16, usage string)

Uint16Var defines a uint16 environment variable with specified name, default value, and usage string. The argument p points to a uint16 variable in which to store the value of the environment variable.

func Uint32

func Uint32(name string, value uint32, usage string) *uint32

Uint32 defines a uint32 environment variable with specified name, default value, and usage string. The return value is the address of a uint32 variable that stores the value of the environment variable.

func Uint32Var

func Uint32Var(p *uint32, name string, value uint32, usage string)

Uint32Var defines a uint32 environment variable with specified name, default value, and usage string. The argument p points to a uint32 variable in which to store the value of the environment variable.

func Uint64

func Uint64(name string, value uint64, usage string) *uint64

Uint64 defines a uint64 environment variable with specified name, default value, and usage string. The return value is the address of a uint64 variable that stores the value of the environment variable.

func Uint64Var

func Uint64Var(p *uint64, name string, value uint64, usage string)

Uint64Var defines a uint64 environment variable with specified name, default value, and usage string. The argument p points to a uint64 variable in which to store the value of the environment variable.

func Uint8

func Uint8(name string, value uint8, usage string) *uint8

Uint8 defines a uint8 environment variable with specified name, default value, and usage string. The return value is the address of a uint8 variable that stores the value of the environment variable.

func Uint8Var

func Uint8Var(p *uint8, name string, value uint8, usage string)

Uint8Var defines a uint8 environment variable with specified name, default value, and usage string. The argument p points to a uint8 variable in which to store the value of the environment variable.

func UintVar

func UintVar(p *uint, name string, value uint, usage string)

UintVar defines a uint environment variable with specified name, default value, and usage string. The argument p points to a uint variable in which to store the value of the environment variable.

func UnquoteUsage added in v0.4.0

func UnquoteUsage(envVar *EnvVar) (name string, usage string)

UnquoteUsage extracts a back-quoted name from the usage string for an environment variable and returns it and the un-quoted usage. Given "a `name` to show" it returns ("name", "a name to show"). If there are no back quotes, the name is an educated guess of the type of the environment variable's value.

func Var

func Var(value Value, name string, usage string)

Var defines an environment variable with the specified name and usage string. The type and value of the variable are represented by the first argument, of type Value, which typically holds a user-defined implementation of Value. For instance, the caller could create an environment variable that turns a comma-separated string into a slice of strings by giving the slice the methods of Value; in particular, Set would decompose the comma-separated string into the slice.

func VisitAll added in v0.7.0

func VisitAll(fn func(*EnvVar))

VisitAll visits the environment variables in lexicographical order or in primordial order if f.SortVars is false, calling fn for each. It visits all variables, even those not set.

Types

type EnvVar added in v0.2.0

type EnvVar struct {
	// Name of the environment variable
	Name string

	// Usage message
	Usage string

	// Value as set
	Value Value

	// DefaultValue is shown in the usage message
	DefaultValue string
}

EnvVar represents the state of an environment variable.

func Lookup added in v0.7.0

func Lookup(name string) *EnvVar

Lookup returns the EnvVar structure of the named environment variable, returning nil if none exists.

func VarE added in v0.3.0

func VarE(value Value, name string, usage string) *EnvVar

VarE is like Var, but returns the created EnvVar.

type EnvVarSet

type EnvVarSet struct {
	// SortVars is used to indicate, if user wants to have sorted environment variables in
	// help/usage messages.
	SortVars bool
	// contains filtered or unexported fields
}

EnvVarSet is a set of defined environment variables.

func NewEnvVarSet

func NewEnvVarSet(errorHandling ErrorHandling) *EnvVarSet

NewEnvVarSet returns a new, empty environment variable set with the specified error handling property and SortFlags set to true.

func (*EnvVarSet) AddEnvVar added in v0.2.0

func (s *EnvVarSet) AddEnvVar(envVar *EnvVar)

AddEnvVar will add the environment variable to the EnvVarSet.

func (*EnvVarSet) Bool

func (s *EnvVarSet) Bool(name string, value bool, usage string) *bool

Bool defines a bool environment variable with specified name, default value, and usage string. The return value is the address of a bool variable that stores the value of the environment variable.

func (*EnvVarSet) BoolVar

func (s *EnvVarSet) BoolVar(p *bool, name string, value bool, usage string)

BoolVar defines a bool environment variable with specified name, default value, and usage string. The argument p points to a bool variable in which to store the value of the environment variable.

func (*EnvVarSet) Duration

func (s *EnvVarSet) Duration(name string, value time.Duration, usage string) *time.Duration

Duration defines a time.Duration environment variable with specified name, default value, and usage string. The return value is the address of a time.Duration variable that stores the value of the environment variable.

func (*EnvVarSet) DurationVar

func (s *EnvVarSet) DurationVar(p *time.Duration, name string, value time.Duration, usage string)

DurationVar defines a time.Duration environment variable with specified name, default value, and usage string. The argument p points to a time.Duration variable in which to store the value of the environment variable.

func (*EnvVarSet) EnvVarUsages added in v0.4.0

func (s *EnvVarSet) EnvVarUsages() string

EnvVarUsages returns a string containing the usage information for all environment variables in the set.

func (*EnvVarSet) EnvVarUsagesWrapped added in v0.5.0

func (s *EnvVarSet) EnvVarUsagesWrapped(cols int) string

EnvVarUsages returns a string containing the usage information for all environment variables in the set. Wrapped to `cols` columns (0 for no wrapping)

func (*EnvVarSet) Float32

func (s *EnvVarSet) Float32(name string, value float32, usage string) *float32

Float32 defines a float32 environment variable with specified name, default value, and usage string. The return value is the address of a float32 variable that stores the value of the environment variable.

func (*EnvVarSet) Float32Var

func (s *EnvVarSet) Float32Var(p *float32, name string, value float32, usage string)

Float32Var defines a float32 environment variable with specified name, default value, and usage string. The argument p points to a float32 variable in which to store the value of the environment variable.

func (*EnvVarSet) Float64

func (s *EnvVarSet) Float64(name string, value float64, usage string) *float64

Float64 defines a float64 environment variable with specified name, default value, and usage string. The return value is the address of a float64 variable that stores the value of the environment variable.

func (*EnvVarSet) Float64Var

func (s *EnvVarSet) Float64Var(p *float64, name string, value float64, usage string)

Float64Var defines a float64 environment variable with specified name, default value, and usage string. The argument p points to a float64 variable in which to store the value of the environment variable.

func (*EnvVarSet) GetNormalizeFunc added in v0.3.0

func (s *EnvVarSet) GetNormalizeFunc() NormalizeFunc

GetNormalizeFunc returns the previously set NormalizeFunc. If not set, it returns the default normalization function.

func (*EnvVarSet) HasEnvVars added in v0.5.0

func (s *EnvVarSet) HasEnvVars() bool

HasEnvVars returns a bool to indicate if the EnvVarSet has any environment variables defined.

func (*EnvVarSet) Int

func (s *EnvVarSet) Int(name string, value int, usage string) *int

Int defines an int environment variable with specified name, default value, and usage string. The return value is the address of an int variable that stores the value of the environment variable.

func (*EnvVarSet) Int16

func (s *EnvVarSet) Int16(name string, value int16, usage string) *int16

Int16 defines an int16 environment variable with specified name, default value, and usage string. The return value is the address of an int16 variable that stores the value of the environment variable.

func (*EnvVarSet) Int16Var

func (s *EnvVarSet) Int16Var(p *int16, name string, value int16, usage string)

Int16Var defines an int16 environment variable with specified name, default value, and usage string. The argument p points to an int16 variable in which to store the value of the environment variable.

func (*EnvVarSet) Int32

func (s *EnvVarSet) Int32(name string, value int32, usage string) *int32

Int32 defines an int32 environment variable with specified name, default value, and usage string. The return value is the address of an int32 variable that stores the value of the environment variable.

func (*EnvVarSet) Int32Var

func (s *EnvVarSet) Int32Var(p *int32, name string, value int32, usage string)

Int32Var defines an int32 environment variable with specified name, default value, and usage string. The argument p points to an int32 variable in which to store the value of the environment variable.

func (*EnvVarSet) Int64

func (s *EnvVarSet) Int64(name string, value int64, usage string) *int64

Int64 defines an int64 environment variable with specified name, default value, and usage string. The return value is the address of an int64 variable that stores the value of the environment variable.

func (*EnvVarSet) Int64Var

func (s *EnvVarSet) Int64Var(p *int64, name string, value int64, usage string)

Int64Var defines an int64 environment variable with specified name, default value, and usage string. The argument p points to an int64 variable in which to store the value of the environment variable.

func (*EnvVarSet) Int8

func (s *EnvVarSet) Int8(name string, value int8, usage string) *int8

Int8 defines an int8 environment variable with specified name, default value, and usage string. The return value is the address of an int8 variable that stores the value of the environment variable.

func (*EnvVarSet) Int8Var

func (s *EnvVarSet) Int8Var(p *int8, name string, value int8, usage string)

Int8Var defines an int8 environment variable with specified name, default value, and usage string. The argument p points to an int8 variable in which to store the value of the environment variable.

func (*EnvVarSet) IntVar

func (s *EnvVarSet) IntVar(p *int, name string, value int, usage string)

IntVar defines an int environment variable with specified name, default value, and usage string. The argument p points to an int variable in which to store the value of the environment variable.

func (*EnvVarSet) Lookup added in v0.7.0

func (s *EnvVarSet) Lookup(name string) *EnvVar

Lookup returns the EnvVar structure of the named environment variable, returning nil if none exists.

func (*EnvVarSet) Parse

func (s *EnvVarSet) Parse(environment map[string]string) error

Parse parses environment variables according to the definitions in the EnvVarSet. Must be called after all variables in the EnvVarSet are defined and before variables are accessed by the program.

func (*EnvVarSet) ParseEnviron

func (s *EnvVarSet) ParseEnviron(environ []string) error

ParseEnviron accepts a list of environment variables in the "key=value" format returned by os.Environ(), transforms it into a string map and calls Parse.

func (*EnvVarSet) Parsed

func (s *EnvVarSet) Parsed() bool

Parsed reports whether Parse has been called on EnvVarSet.

func (*EnvVarSet) PrintDefaults added in v0.5.0

func (s *EnvVarSet) PrintDefaults()

PrintDefaults prints, to standard error unless configured otherwise, the default values of all defined environment variables in the set.

func (*EnvVarSet) QueryString added in v0.5.0

func (s *EnvVarSet) QueryString(name string, value map[string]string, usage string) *map[string]string

QueryString defines a query string environment variable with specified name, default value, and usage string. The return value is the address of a query string (string map) variable that stores the value of the environment variable.

func (*EnvVarSet) QueryStringVar added in v0.5.0

func (s *EnvVarSet) QueryStringVar(p *map[string]string, name string, value map[string]string, usage string)

QueryStringVar defines a query string environment variable with specified name, default value, and usage string. The argument p points to a query string (string map) variable in which to store the value of the environment variable.

func (*EnvVarSet) SetNormalizeFunc added in v0.3.0

func (s *EnvVarSet) SetNormalizeFunc(fn NormalizeFunc)

SetNormalizeFunc allows you to add a function which can translate variable names. Environment variables added to the EnvVarSet will be translated, incoming environment variables will be matched against these translated names.

func (*EnvVarSet) SetOutput added in v0.2.0

func (s *EnvVarSet) SetOutput(output io.Writer)

SetOutput sets the destination for usage and error messages. If output is nil, os.Stderr is used.

func (*EnvVarSet) String

func (s *EnvVarSet) String(name string, value string, usage string) *string

String defines a string environment variable with specified name, default value, and usage string. The return value is the address of a string variable that stores the value of the environment variable.

func (*EnvVarSet) StringSlice added in v0.6.0

func (s *EnvVarSet) StringSlice(name string, value []string, usage string) *[]string

StringSlice defines a string environment variable with specified name, default value, and usage string. The return value is the address of a []string variable that stores the value of the environment variable. For example:

STRING_SLICE="v1,v2"

will result in

[]string{"v1", "v2"}

func (*EnvVarSet) StringSliceVar added in v0.6.0

func (s *EnvVarSet) StringSliceVar(p *[]string, name string, value []string, usage string)

StringSliceVar defines a string environment variable with specified name, default value, and usage string. The argument p points to a []string variable in which to store the value of the environment variable. For example:

STRING_SLICE="v1,v2"

will result in

[]string{"v1", "v2"}

func (*EnvVarSet) StringVar

func (s *EnvVarSet) StringVar(p *string, name string, value string, usage string)

StringVar defines a string environment variable with specified name, default value, and usage string. The argument p points to a string variable in which to store the value of the environment variable.

func (*EnvVarSet) Uint

func (s *EnvVarSet) Uint(name string, value uint, usage string) *uint

Uint defines a uint environment variable with specified name, default value, and usage string. The return value is the address of a uint variable that stores the value of the environment variable.

func (*EnvVarSet) Uint16

func (s *EnvVarSet) Uint16(name string, value uint16, usage string) *uint16

Uint16 defines a uint16 environment variable with specified name, default value, and usage string. The return value is the address of a uint16 variable that stores the value of the environment variable.

func (*EnvVarSet) Uint16Var

func (s *EnvVarSet) Uint16Var(p *uint16, name string, value uint16, usage string)

Uint16Var defines a uint16 environment variable with specified name, default value, and usage string. The argument p points to a uint16 variable in which to store the value of the environment variable.

func (*EnvVarSet) Uint32

func (s *EnvVarSet) Uint32(name string, value uint32, usage string) *uint32

Uint32 defines a uint32 environment variable with specified name, default value, and usage string. The return value is the address of a uint32 variable that stores the value of the environment variable.

func (*EnvVarSet) Uint32Var

func (s *EnvVarSet) Uint32Var(p *uint32, name string, value uint32, usage string)

Uint32Var defines a uint32 environment variable with specified name, default value, and usage string. The argument p points to a uint32 variable in which to store the value of the environment variable.

func (*EnvVarSet) Uint64

func (s *EnvVarSet) Uint64(name string, value uint64, usage string) *uint64

Uint64 defines a uint64 environment variable with specified name, default value, and usage string. The return value is the address of a uint64 variable that stores the value of the environment variable.

func (*EnvVarSet) Uint64Var

func (s *EnvVarSet) Uint64Var(p *uint64, name string, value uint64, usage string)

Uint64Var defines a uint64 environment variable with specified name, default value, and usage string. The argument p points to a uint64 variable in which to store the value of the environment variable.

func (*EnvVarSet) Uint8

func (s *EnvVarSet) Uint8(name string, value uint8, usage string) *uint8

Uint8 defines a uint8 environment variable with specified name, default value, and usage string. The return value is the address of a uint8 variable that stores the value of the environment variable.

func (*EnvVarSet) Uint8Var

func (s *EnvVarSet) Uint8Var(p *uint8, name string, value uint8, usage string)

Uint8Var defines a uint8 environment variable with specified name, default value, and usage string. The argument p points to a uint8 variable in which to store the value of the environment variable.

func (*EnvVarSet) UintVar

func (s *EnvVarSet) UintVar(p *uint, name string, value uint, usage string)

UintVar defines a uint environment variable with specified name, default value, and usage string. The argument p points to a uint variable in which to store the value of the environment variable.

func (*EnvVarSet) Var

func (s *EnvVarSet) Var(value Value, name string, usage string)

Var defines an environment variable with the specified name and usage string. The type and value of the variable are represented by the first argument, of type Value, which typically holds a user-defined implementation of Value. For instance, the caller could create an environment variable that turns a comma-separated string into a slice of strings by giving the slice the methods of Value; in particular, Set would decompose the comma-separated string into the slice.

func (*EnvVarSet) VarE added in v0.3.0

func (s *EnvVarSet) VarE(value Value, name string, usage string) *EnvVar

VarE is like Var, but returns the created EnvVar.

func (*EnvVarSet) VisitAll added in v0.7.0

func (s *EnvVarSet) VisitAll(fn func(*EnvVar))

VisitAll visits the environment variables in lexicographical order or in primordial order if f.SortVars is false, calling fn for each. It visits all variables, even those not set.

type ErrorHandling

type ErrorHandling int

ErrorHandling defines how to handle env var parsing errors.

const (
	// ContinueOnError will return an err from Parse() if an error is found
	ContinueOnError ErrorHandling = iota

	// ExitOnError will call os.Exit(2) if an error is found
	ExitOnError

	// PanicOnError will panic() if an error is found
	PanicOnError
)

type NormalizeFunc added in v0.3.0

type NormalizeFunc func(s *EnvVarSet, name string) NormalizedName

NormalizeFunc normalizes an environment variable name to the form it can be found in the environment.

type NormalizedName added in v0.3.0

type NormalizedName string

NormalizedName is an environment variable name that has been normalized according to rules for the EnvVarSet (e.g. making variable names upper case, adding prefixes, etc).

func DefaultNormalizeFunc added in v0.3.0

func DefaultNormalizeFunc(_ *EnvVarSet, name string) NormalizedName

DefaultNormalizeFunc formats variable names to upper case and replaces "-." chars with "_".

type Value

type Value interface {
	// Set is responsible for converting the string value to the actual type
	// and setting it in the target variable.
	//
	// When the conversion fails an error should be returned.
	Set(string) error

	// Type returns the name of the type the value represents.
	Type() string

	// String returns the actual value as string.
	//
	// Before any environment parsing happens, the returned value will be the default value.
	String() string
}

Value is the interface to the dynamic value stored in an environment variable. (The default value is represented as a string.)

Jump to

Keyboard shortcuts

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