All Projects → gobuffalo → Envy

gobuffalo / Envy

Licence: mit
Envy makes working with ENV variables in Go trivial.

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Envy

Hyperapp Html
Html helper functions for Hyperapp V1
Stars: ✭ 83 (-35.16%)
Mutual labels:  helpers
Xlswiftkit
Helpers and extensions for Swift
Stars: ✭ 96 (-25%)
Mutual labels:  helpers
Geoman
Tensorflow Implement of GeoMAN, IJCAI-18
Stars: ✭ 113 (-11.72%)
Mutual labels:  environment
Grabs
Front-End Development Environment
Stars: ✭ 89 (-30.47%)
Mutual labels:  environment
Envh
Go helpers to manage environment variables
Stars: ✭ 95 (-25.78%)
Mutual labels:  environment
Helpers
A collection of Javascript String and Array helpers for Laravel developers
Stars: ✭ 108 (-15.62%)
Mutual labels:  helpers
Awesome Zeit
The best resources related to ZEIT
Stars: ✭ 1,242 (+870.31%)
Mutual labels:  helpers
Vivify
Vivify is free CSS animation library.
Stars: ✭ 1,651 (+1189.84%)
Mutual labels:  helpers
Shellfuncs
Python API to execute shell functions as they would be Python functions
Stars: ✭ 96 (-25%)
Mutual labels:  environment
Yakutils
🐃 Yet another toolbox of Python 3 helper functions.
Stars: ✭ 111 (-13.28%)
Mutual labels:  helpers
Alfonz
Mr. Alfonz is here to help you build your Android app, make the development process easier and avoid boilerplate code.
Stars: ✭ 90 (-29.69%)
Mutual labels:  helpers
Beetbox
Pre-provisioned L*MP stack
Stars: ✭ 94 (-26.56%)
Mutual labels:  environment
Termux Extra Packages
Stars: ✭ 110 (-14.06%)
Mutual labels:  environment
Homies
linux package management
Stars: ✭ 86 (-32.81%)
Mutual labels:  environment
Zparkio
Boiler plate framework to use Spark and ZIO together.
Stars: ✭ 121 (-5.47%)
Mutual labels:  helpers
Sequelize Test Helpers
A collection of utilities to help with unit-testing Sequelize models
Stars: ✭ 83 (-35.16%)
Mutual labels:  helpers
Drupal Vm
A VM for Drupal development
Stars: ✭ 1,348 (+953.13%)
Mutual labels:  environment
Slate Language
The Slate programming language
Stars: ✭ 127 (-0.78%)
Mutual labels:  environment
Codability
Useful helpers for working with Codable types in Swift
Stars: ✭ 125 (-2.34%)
Mutual labels:  helpers
Rails stuff
Collection of useful modules for Rails.
Stars: ✭ 110 (-14.06%)
Mutual labels:  helpers

envy

Build Status

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)
  • More!

Installation

$ go get -u github.com/gobuffalo/envy

Usage

func Test_Get(t *testing.T) {
	r := require.New(t)
	r.NotZero(os.Getenv("GOPATH"))
	r.Equal(os.Getenv("GOPATH"), envy.Get("GOPATH", "foo"))
	r.Equal("bar", envy.Get("IDONTEXIST", "bar"))
}

func Test_MustGet(t *testing.T) {
	r := require.New(t)
	r.NotZero(os.Getenv("GOPATH"))
	v, err := envy.MustGet("GOPATH")
	r.NoError(err)
	r.Equal(os.Getenv("GOPATH"), v)

	_, err = envy.MustGet("IDONTEXIST")
	r.Error(err)
}

func Test_Set(t *testing.T) {
	r := require.New(t)
	_, err := envy.MustGet("FOO")
	r.Error(err)

	envy.Set("FOO", "foo")
	r.Equal("foo", envy.Get("FOO", "bar"))
}

func Test_Temp(t *testing.T) {
	r := require.New(t)

	_, err := envy.MustGet("BAR")
	r.Error(err)

	envy.Temp(func() {
		envy.Set("BAR", "foo")
		r.Equal("foo", envy.Get("BAR", "bar"))
		_, err = envy.MustGet("BAR")
		r.NoError(err)
	})

	_, err = envy.MustGet("BAR")
	r.Error(err)
}

.env files support

Envy now supports loading .env files by using the godotenv library. That means one can use and define multiple .env files which will be loaded on-demand. By default, no env files will be loaded. To load one or more, you need to call the envy.Load function in one of the following ways:

envy.Load() // 1

envy.Load("MY_ENV_FILE") // 2

envy.Load(".env", ".env.prod") // 3

envy.Load(".env", "NON_EXISTING_FILE") // 4

// 5
envy.Load(".env")
envy.Load("NON_EXISTING_FILE")

// 6
envy.Load(".env", "NON_EXISTING_FILE", ".env.prod")
  1. Will load the default .env file
  2. Will load the file MY_ENV_FILE, but not .env
  3. Will load the file .env, and after that will load the .env.prod file. If any variable is redefined in . env.prod it will be overwritten (will contain the env.prod value)
  4. Will load the .env file and return an error as the second file does not exist. The values in .env will be loaded and available.
  5. Same as 4
  6. Will load the .env file and return an error as the second file does not exist. The values in .env will be loaded and available, but the ones in .env.prod won't.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].