Documentation ¶
Overview ¶
Package envcfg provides a common way to load configuration variables from the system environment or from based on initial configuration values stored on disk or in a base64 encoded environment variable.
Index ¶
- Constants
- type Envcfg
- func (ec *Envcfg) Env() string
- func (ec *Envcfg) GetBool(key string) bool
- func (ec *Envcfg) GetDuration(key string) time.Duration
- func (ec *Envcfg) GetFloat(key string, bitSize int) float64
- func (ec *Envcfg) GetInt(key string) int
- func (ec *Envcfg) GetInt64(key string, base, bitSize int) int64
- func (ec *Envcfg) GetKey(key string) string
- func (ec *Envcfg) GetString(key string) string
- func (ec *Envcfg) GetUint64(key string, base, bitSize int) uint64
- func (ec *Envcfg) Host() string
- func (ec *Envcfg) MustInt(key string) int
- func (ec *Envcfg) MustKey(key string) string
- func (ec *Envcfg) Port() int
- func (ec *Envcfg) PortString() string
- func (ec *Envcfg) TLS() *tls.Config
- type Option
- func CertDelayKey(key string) Option
- func CertPathKey(key string) Option
- func CertWaitKey(key string) Option
- func ConfigFile(path string) Option
- func EnvKey(key string) Option
- func Errorf(f func(string, ...interface{})) Option
- func HostKey(key string) Option
- func Logf(f func(string, ...interface{})) Option
- func PortKey(key string) Option
- func VarName(name string) Option
Constants ¶
const ( // DefaultVarName is the default environment variable name to load the // initial configuration data from. DefaultVarName = "APP_CONFIG" // DefaultEnvKey is the default runtime environment key. DefaultEnvKey = "runtime.environment" // DefaultHostKey is the default server hostname key. DefaultHostKey = "server.host" // DefaultPortKey is the default server port key. DefaultPortKey = "server.port" // DefaultCertPathKey is the default server certificate path key. DefaultCertPathKey = "server.certs" // DefaultCertProviderKey is the default server certificate provider key. DefaultCertProviderKey = "server.certProvider" // DefaultCertWaitKey is the default server certificate wait key. DefaultCertWaitKey = "server.certWait" // DefaultCertDelayKey is the default server certificate delay key. DefaultCertDelayKey = "server.certDelay" // DefaultConfigFile is the default file path to load the initial // configuration data from. DefaultConfigFile = "env/config" // DefaultCertPath is the default certificate caching path. DefaultCertPath = "env/certs" // DefaultEnvironment is the default environment name. DefaultEnvironment = "development" // DefaultCertWait is the default certificate provider wait duration. DefaultCertWait = 180 * time.Second // DefaultCertDelay is the default certificate provider propagation delay. DefaultCertDelay = 30 * time.Second )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Envcfg ¶
type Envcfg struct {
// contains filtered or unexported fields
}
Envcfg handles loading configuration variables from system environment variables or from an initial configuration file.
func (*Envcfg) GetBool ¶
GetBool retrieves the value for key from the environment, or the supplied configuration data, returning it as a bool.
func (*Envcfg) GetDuration ¶
GetDuration retrievses the value for key from the environment, or the supplied configuration data, returning it as a time.Duration.
func (*Envcfg) GetFloat ¶
GetFloat retrieves the value for key from the environment, or the supplied configuration data, returning it as a float64. Uses bitSize as the precision.
func (*Envcfg) GetInt ¶
GetInt retrieves the value for key from the environment, or the supplied configuration data, returning it as a int. Expects numbers to be base 10 and no larger than 32 bits.
func (*Envcfg) GetInt64 ¶
GetInt64 retrieves the value for key from the environment, or the supplied configuration data, returning it as a int64. Uses base and bitSize to parse.
func (*Envcfg) GetKey ¶
GetKey retrieves the value for the key from the environment, or from the initial supplied configuration data.
When the initial value read from the config file or the supplied app environment variable is in the form of "$NAME||<default>" or "$NAME||<default>||<encoding>". Then the value will be read from from the system environment variable $NAME. If that value is empty, then the <default> value will be returned instead. If the third, optional parameter is supplied then the environment variable value (or the default value) will be decoded using the appropriate method.
Current supported <encoding> parameters:
base64 -- value should be base64 decoded file -- value should be read from disk relfile -- value should be read from a path on disk relative to the loaded file
func (*Envcfg) GetString ¶
GetString retrieves the value for key from the environment or the supplied configuration data, returning it as a string.
NOTE: alias for GetKey.
func (*Envcfg) GetUint64 ¶
GetUint64 retrieves the value for key from the environment, or the supplied configuration data, returning it as a uint64. Uses base and bitSize to parse.
func (*Envcfg) MustInt ¶
MustInt returns the value for key (same as GetInt) but panics if the key was blank or if the value is an invalid int.
func (*Envcfg) MustKey ¶
MustKey returns the value for key (same as GetKey) but panics if the string is empty.
func (*Envcfg) PortString ¶
PortString retrieves the value for the server port key as a string.
type Option ¶
type Option func(*Envcfg)
Option is an Envcfg option.
func CertDelayKey ¶
CertDelayKey is an option that sets the server certificate delay key.
func CertPathKey ¶
CertPathKey is an option that sets the server certificate path key.
func CertWaitKey ¶
CertWaitKey is an option that sets the server certificate wait key.
func ConfigFile ¶
ConfigFile is an option that sets the file path to read data from.