Documentation ¶
Overview ¶
Package env contains environment variable helpers, enabling better tests and easier use of environment variables.
Index ¶
- Constants
- func Restore()
- func SetEnv(vars Vars)
- type Unmarshaler
- type Vars
- func (ev Vars) Base64(envVar string, defaults ...[]byte) ([]byte, error)
- func (ev Vars) Bool(envVar string, defaults ...bool) bool
- func (ev Vars) Bytes(envVar string, defaults ...[]byte) []byte
- func (ev Vars) CSV(envVar string, defaults ...string) []string
- func (ev Vars) Delete(key string)
- func (ev Vars) Duration(envVar string, defaults ...time.Duration) (time.Duration, error)
- func (ev Vars) Float64(envVar string, defaults ...float64) (float64, error)
- func (ev Vars) Has(envVar string) bool
- func (ev Vars) HasAll(envVars ...string) bool
- func (ev Vars) HasAny(envVars ...string) bool
- func (ev Vars) Int(envVar string, defaults ...int) (int, error)
- func (ev Vars) Int32(envVar string, defaults ...int32) (int32, error)
- func (ev Vars) Int64(envVar string, defaults ...int64) (int64, error)
- func (ev Vars) IsProdlike() bool
- func (ev Vars) IsProduction() bool
- func (ev Vars) Must(keys ...string)
- func (ev Vars) MustBase64(envVar string, defaults ...[]byte) []byte
- func (ev Vars) MustDuration(envVar string, defaults ...time.Duration) time.Duration
- func (ev Vars) MustFloat64(envVar string, defaults ...float64) float64
- func (ev Vars) MustInt(envVar string, defaults ...int) int
- func (ev Vars) MustInt32(envVar string, defaults ...int32) int32
- func (ev Vars) MustInt64(envVar string, defaults ...int64) int64
- func (ev Vars) MustUint32(envVar string, defaults ...uint32) uint32
- func (ev Vars) MustUint64(envVar string, defaults ...uint64) uint64
- func (ev Vars) Raw() []string
- func (ev Vars) ReadFile(path string) error
- func (ev Vars) ReadInto(obj interface{}) error
- func (ev Vars) Require(keys ...string) error
- func (ev Vars) Restore(key string)
- func (ev Vars) ServiceEnv(defaults ...string) string
- func (ev Vars) ServiceName(defaults ...string) string
- func (ev Vars) Set(envVar, value string)
- func (ev Vars) String(envVar string, defaults ...string) string
- func (ev Vars) Uint32(envVar string, defaults ...uint32) (uint32, error)
- func (ev Vars) Uint64(envVar string, defaults ...uint64) (uint64, error)
- func (ev Vars) Union(other Vars) Vars
- func (ev Vars) Vars() []string
Constants ¶
const ( // VarServiceEnv is a common env var name. VarServiceEnv = "SERVICE_ENV" // VarServiceName is a common env var name. VarServiceName = "SERVICE_NAME" // VarServiceSecret is a common env var name. VarServiceSecret = "SERVICE_SECRET" // VarPort is a common env var name. VarPort = "PORT" // VarSecurePort is a common env var name. VarSecurePort = "SECURE_PORT" // VarTLSCertPath is a common env var name. VarTLSCertPath = "TLS_CERT_PATH" // VarTLSKeyPath is a common env var name. VarTLSKeyPath = "TLS_KEY_PATH" // VarTLSCert is a common env var name. VarTLSCert = "TLS_CERT" // VarTLSKey is a common env var name. VarTLSKey = "TLS_KEY" // VarPGIdleConns is a common env var name. VarPGIdleConns = "PG_IDLE_CONNS" // VarPGMaxConns is a common env var name. VarPGMaxConns = "PG_MAX_CONNS" // ServiceEnvTest is a service environment. ServiceEnvTest = "test" // ServiceEnvSandbox is a service environment. ServiceEnvSandbox = "sandbox" // ServiceEnvDev is a service environment. ServiceEnvDev = "dev" // ServiceEnvCI is a service environment. ServiceEnvCI = "ci" // ServiceEnvPreprod is a service environment. ServiceEnvPreprod = "preprod" // ServiceEnvBeta is a service environment. ServiceEnvBeta = "beta" // ServiceEnvProd is a service environment. ServiceEnvProd = "prod" // TagName is the reflection tag name. TagName = "env" )
Service specific constants
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Unmarshaler ¶
Unmarshaler is a type that implements `UnmarshalEnv`.
type Vars ¶
Vars is a set of environment variables.
func NewVarsFromEnvironment ¶
func NewVarsFromEnvironment() Vars
NewVarsFromEnvironment reads an EnvVar set from the environment.
func (Vars) Base64 ¶
Base64 returns a []byte value for a given key whose value is encoded in base64.
func (Vars) Bool ¶
Bool returns a boolean value for a key, defaulting to false. Valid "truthy" values are `true`, `yes`, and `1`. Everything else is false, including `REEEEEEEEEEEEEEE`.
func (Vars) IsProdlike ¶
IsProdlike returns if the ServiceEnv is "prodlike".
func (Vars) IsProduction ¶
IsProduction returns if the ServiceEnv is a production environment.
func (Vars) Must ¶
Must enforces that a given set of environment variables are present and panics if they're not present.
func (Vars) MustBase64 ¶
MustBase64 returns a []byte value for a given key encoded with base64, and panics if malformed.
func (Vars) MustDuration ¶
MustDuration returnss a duration value for a given key and panics if malformed.
func (Vars) MustFloat64 ¶
MustFloat64 returns an float64 value for a given key and panics if it is malformed.
func (Vars) MustInt ¶
MustInt returns an integer value for a given key and panics if it is malformed.
func (Vars) MustInt32 ¶
MustInt32 returns an integer value for a given key and panics if it is malformed.
func (Vars) MustInt64 ¶
MustInt64 returns an int64 value for a given key and panics if it is malformed.
func (Vars) MustUint32 ¶
MustUint32 returns an uint32 value for a given key and panics if it is malformed.
func (Vars) MustUint64 ¶
MustUint64 returns an uint64 value for a given key and panics if it is malformed.
func (Vars) ServiceEnv ¶
ServiceEnv is a common environment variable for the services environment. Common values include "dev", "ci", "sandbox", "preprod", "beta", and "prod".
func (Vars) ServiceName ¶
ServiceName is a common environment variable for the service's name.