enviroment

package
v0.0.0-...-0fdeed9 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(key string) (string, error)

Get a key from the proper enviroment.

func Init

func Init(prodCheck IsProductionEnviroment) error

Init the enviroment based on whether or not we are in production or not.

func IsDevelopment

func IsDevelopment() bool

IsDevelopment returns whether or not we are in a development enviroment.

func IsProduction

func IsProduction() bool

IsProduction returns whether or not we are in a production enviroment.

func SetDevelopmentLoader

func SetDevelopmentLoader(loader Loader)

SetDevelopmentLoader setss an enviroment variable loader for the development enviroment. If the enviroment is development, this loader will be used.

func SetProductionLoader

func SetProductionLoader(loader Loader)

SetProductionLoader sets an enviroment variable loader for the production enviroment. If the enviroment is production, this loader will be used.

func SetRequiredVariables

func SetRequiredVariables(vars []string)

SetRequiredVariables stores an array of required enviroment variables for optimal execution. This is used as a check upon initialization to ensure that the enviroment has all required variables.

Types

type DotEnvLoader

type DotEnvLoader struct{}

DotEnvLoader loads enviroment variables from a .env file.

func (*DotEnvLoader) Get

func (de *DotEnvLoader) Get(key string) (string, error)

Get an enviroment variable from the users enviroment. Note that the dotenv loader will load any variables from the .env file to the enviroment.

func (*DotEnvLoader) Init

func (de *DotEnvLoader) Init() error

Init an DotEnvLoader which loads the enviroment variables in the .env file to the os enviroment.

type EnvLoader

type EnvLoader struct{}

EnvLoader loads enviroment variable from the users enviroment. This loader is best used in a development enviroment, where developers can put required enviroment variables in their ~/.bashrc or ~/.zshrc files.

func (*EnvLoader) Get

func (el *EnvLoader) Get(key string) (string, error)

Get an enviroment variable from the users enviroment.

func (*EnvLoader) Init

func (el *EnvLoader) Init() error

Init an EnvLoader. This does nothing since initialization isn't required for this type of enviroment.

type GCEMetadataLoader

type GCEMetadataLoader struct{}

GCEMetadataLoader is used to load enviromental data from the GCE project attribute keys. Note that this will only work if we are on a GCE instance.

func (*GCEMetadataLoader) Get

func (gce *GCEMetadataLoader) Get(key string) (string, error)

Get a key from the GCE Metadata server.

func (*GCEMetadataLoader) Init

func (gce *GCEMetadataLoader) Init() error

Init the GCEMetadataLoader. This function checks that we are indeed on a google compute engine instance.

type IsProductionEnviroment

type IsProductionEnviroment func() bool

IsProductionEnviroment defines logic for checking if we are in production.

type Loader

type Loader interface {
	Init() error
	Get(key string) (string, error)
}

Loader is an interface for an enviromental loader. This is used to retrieve data from the enviroment in a generic way.

type Type

type Type int

Type is an enumeration over the possible enviroment types.

const (
	// TypeDevelopment represents a development enviroment.
	TypeDevelopment Type = 0
	// TypeProduction represents a production enviroment.
	TypeProduction Type = 1
)

Jump to

Keyboard shortcuts

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