env

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2018 License: MIT Imports: 7 Imported by: 9

Documentation

Overview

Package env contains environment variable helpers, enabling better tests and easier use of environment variables.

Index

Constants

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

func Restore

func Restore()

Restore sets .Env() to the current os environment.

func SetEnv

func SetEnv(vars Vars)

SetEnv sets the env vars.

Types

type Unmarshaler

type Unmarshaler interface {
	UnmarshalEnv(vars Vars) error
}

Unmarshaler is a type that implements `UnmarshalEnv`.

type Vars

type Vars map[string]string

Vars is a set of environment variables.

func Env

func Env() Vars

Env returns the current env var set.

func NewVars

func NewVars() Vars

NewVars returns a new env var set.

func NewVarsFromEnvironment

func NewVarsFromEnvironment() Vars

NewVarsFromEnvironment reads an EnvVar set from the environment.

func (Vars) Base64

func (ev Vars) Base64(envVar string, defaults ...[]byte) ([]byte, error)

Base64 returns a []byte value for a given key whose value is encoded in base64.

func (Vars) Bool

func (ev Vars) Bool(envVar string, defaults ...bool) 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) Bytes

func (ev Vars) Bytes(envVar string, defaults ...[]byte) []byte

Bytes returns a []byte value for a given key.

func (Vars) CSV

func (ev Vars) CSV(envVar string, defaults ...string) []string

CSV returns a string array for a given string var.

func (Vars) Delete

func (ev Vars) Delete(key string)

Delete removes a key from the set.

func (Vars) Duration

func (ev Vars) Duration(envVar string, defaults ...time.Duration) (time.Duration, error)

Duration returns a duration value for a given key.

func (Vars) Float64

func (ev Vars) Float64(envVar string, defaults ...float64) (float64, error)

Float64 returns an float64 value for a given key.

func (Vars) Has

func (ev Vars) Has(envVar string) bool

Has returns if a key is present in the set.

func (Vars) HasAll

func (ev Vars) HasAll(envVars ...string) bool

HasAll returns if all of the given vars are present in the set.

func (Vars) HasAny

func (ev Vars) HasAny(envVars ...string) bool

HasAny returns if any of the given vars are present in the set.

func (Vars) Int

func (ev Vars) Int(envVar string, defaults ...int) (int, error)

Int returns an integer value for a given key.

func (Vars) Int32

func (ev Vars) Int32(envVar string, defaults ...int32) (int32, error)

Int32 returns an integer value for a given key.

func (Vars) Int64

func (ev Vars) Int64(envVar string, defaults ...int64) (int64, error)

Int64 returns an int64 value for a given key.

func (Vars) IsProdlike

func (ev Vars) IsProdlike() bool

IsProdlike returns if the ServiceEnv is "prodlike".

func (Vars) IsProduction

func (ev Vars) IsProduction() bool

IsProduction returns if the ServiceEnv is a production environment.

func (Vars) Must

func (ev Vars) Must(keys ...string)

Must enforces that a given set of environment variables are present and panics if they're not present.

func (Vars) MustBase64

func (ev Vars) MustBase64(envVar string, defaults ...[]byte) []byte

MustBase64 returns a []byte value for a given key encoded with base64, and panics if malformed.

func (Vars) MustDuration

func (ev Vars) MustDuration(envVar string, defaults ...time.Duration) time.Duration

MustDuration returnss a duration value for a given key and panics if malformed.

func (Vars) MustFloat64

func (ev Vars) MustFloat64(envVar string, defaults ...float64) float64

MustFloat64 returns an float64 value for a given key and panics if it is malformed.

func (Vars) MustInt

func (ev Vars) MustInt(envVar string, defaults ...int) int

MustInt returns an integer value for a given key and panics if it is malformed.

func (Vars) MustInt32

func (ev Vars) MustInt32(envVar string, defaults ...int32) int32

MustInt32 returns an integer value for a given key and panics if it is malformed.

func (Vars) MustInt64

func (ev Vars) MustInt64(envVar string, defaults ...int64) int64

MustInt64 returns an int64 value for a given key and panics if it is malformed.

func (Vars) MustUint32

func (ev Vars) MustUint32(envVar string, defaults ...uint32) uint32

MustUint32 returns an uint32 value for a given key and panics if it is malformed.

func (Vars) MustUint64

func (ev Vars) MustUint64(envVar string, defaults ...uint64) uint64

MustUint64 returns an uint64 value for a given key and panics if it is malformed.

func (Vars) Raw

func (ev Vars) Raw() []string

Raw returns a raw KEY=VALUE form of the vars.

func (Vars) ReadFile

func (ev Vars) ReadFile(path string) error

ReadFile reads a file from the env.

func (Vars) ReadInto

func (ev Vars) ReadInto(obj interface{}) error

ReadInto sets an object based on the fields in the env vars set.

func (Vars) Require

func (ev Vars) Require(keys ...string) error

Require enforces that a given set of environment variables are present.

func (Vars) Restore

func (ev Vars) Restore(key string)

Restore resets an environment variable to it's environment value.

func (Vars) ServiceEnv

func (ev Vars) ServiceEnv(defaults ...string) string

ServiceEnv is a common environment variable for the services environment. Common values include "dev", "ci", "sandbox", "preprod", "beta", and "prod".

func (Vars) ServiceName

func (ev Vars) ServiceName(defaults ...string) string

ServiceName is a common environment variable for the service's name.

func (Vars) Set

func (ev Vars) Set(envVar, value string)

Set sets a value for a key.

func (Vars) String

func (ev Vars) String(envVar string, defaults ...string) string

String returns a string value for a given key, with an optional default vaule.

func (Vars) Uint32

func (ev Vars) Uint32(envVar string, defaults ...uint32) (uint32, error)

Uint32 returns an uint32 value for a given key.

func (Vars) Uint64

func (ev Vars) Uint64(envVar string, defaults ...uint64) (uint64, error)

Uint64 returns an uint64 value for a given key.

func (Vars) Union

func (ev Vars) Union(other Vars) Vars

Union returns the union of the two sets, other replacing conflicts.

func (Vars) Vars

func (ev Vars) Vars() []string

Vars returns all the vars stored in the env var set.

Jump to

Keyboard shortcuts

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