env

package
v0.0.0-...-5818010 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2019 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package env standardizes environment names for use in environment based switching and implements both a flag and an environment variable for managing what environment the binary should currently be operating under.

Although both flag and envflag may be imported at the same time for different uses (e.g. flag for '-v' and '-h', envflag for 'ENV=production', only one or the other should be used to declare the environment; never both at the same time.

In addition, this package is able to detect whether or not a given program is being run under a continuous integration system, such as Drone, Jenkins, etc.

Index

Constants

View Source
const (
	Production  = "production"
	Development = "development"
	Staging     = "staging"
)

Production, Development, Staging, and Testing are the runtime environments which are recognized by the env package.

Variables

View Source
var (
	// Env is the current environment specified by flag or envflag.
	// TODO: should have an Unknown env state, since the Env variable is not
	// guaranteed to be set properly if used directly (not through access functions).
	Env string
)

Functions

func InTestCode

func InTestCode() bool

InTestCode returns true if currently running Go test code.

func IsCI

func IsCI() bool

IsCI returns boolean true if the program is being run under a continuous integration environment, and false otherwise.

func IsDevelopment

func IsDevelopment() bool

IsDevelopment returns boolean true if the current environment is "development", and false otherwise.

func IsProduction

func IsProduction() bool

IsProduction returns boolean true if the current environment is "production", and false otherwise.

func IsProductionLike

func IsProductionLike() bool

IsProductionLike returns boolean true if the environment is an actual prod-like environment

func IsStaging

func IsStaging() bool

IsStaging returns boolean true if the current environment is "staging", and false otherwise.

func Name

func Name() string

Name returns the current environment name. This works even during program initialization, where env.Env would always return "Development".

Types

This section is empty.

Jump to

Keyboard shortcuts

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