envy: github.com/gobuffalo/envy Index | Files | Directories

package envy

import "github.com/gobuffalo/envy"

package envy makes working with ENV variables in Go trivial.

* Get ENV variables with default values. * Set ENV variables safely without affecting the underlying system. * Temporarily change ENV vars; useful for testing. * Map all of the key/values in the ENV. * Loads .env files (by using [godotenv](https://github.com/joho/godotenv/)) * More!

Index

Package Files

envy.go version.go

Constants

const GO111MODULE = "GO111MODULE"

GO111MODULE is ENV for turning mods on/off

const Version = "v1.6.11"

func CurrentModule Uses

func CurrentModule() (string, error)

CurrentModule will attempt to return the module name from `go.mod` if modules are enabled. If modules are not enabled it will fallback to using CurrentPackage instead.

func CurrentPackage Uses

func CurrentPackage() string

CurrentPackage attempts to figure out the current package name from the PWD Use CurrentModule for a more accurate package name.

func Environ Uses

func Environ() []string

func Get Uses

func Get(key string, value string) string

Get a value from the ENV. If it doesn't exist the default value will be returned.

func GoBin Uses

func GoBin() string

func GoPath Uses

func GoPath() string

func GoPaths Uses

func GoPaths() []string

GoPaths returns all possible GOPATHS that are set.

func Load Uses

func Load(files ...string) error

Load .env files. Files will be loaded in the same order that are received. Redefined vars will override previously existing values. IE: envy.Load(".env", "test_env/.env") will result in DIR=test_env If no arg passed, it will try to load a .env file.

func Map Uses

func Map() map[string]string

Map all of the keys/values set in envy.

func Mods Uses

func Mods() bool

func MustGet Uses

func MustGet(key string) (string, error)

Get a value from the ENV. If it doesn't exist an error will be returned

func MustSet Uses

func MustSet(key string, value string) error

MustSet the value into the underlying ENV, as well as envy. This may return an error if there is a problem setting the underlying ENV value.

func Reload Uses

func Reload()

Reload the ENV variables. Useful if an external ENV manager has been used

func Set Uses

func Set(key string, value string)

Set a value into the ENV. This is NOT permanent. It will only affect values accessed through envy.

func Temp Uses

func Temp(f func())

Temp makes a copy of the values and allows operation on those values temporarily during the run of the function. At the end of the function run the copy is discarded and the original values are replaced. This is useful for testing. Warning: This function is NOT safe to use from a goroutine or from code which may access any Get or Set function from a goroutine

Directories

PathSynopsis
packrdYou can use the "packr2 clean" command to clean up this, and any other packr generated files.

Package envy imports 12 packages (graph) and is imported by 167 packages. Updated 2018-12-08. Refresh now. Tools for package owners.