env

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

README

Env

The core/env package provides functionality for ensuring we retrieve an environment variable

Example

Loading default environment config
env.TryLoadDefault()
Loading default environment config together with other source
env.TryLoadDefault("package/other.env")
Expect environment variable to be set
dbURL := env.MustGet("DATABASE_URL")

Documentation

Overview

Package env provides functionality for ensuring we retrieve an environment variable

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustGet

func MustGet(name string) string

MustGet returns an environment variable by name If the requested variable does not exist, we throw a fatal error

Example
package main

import (
	"log"

	"github.com/LUSHDigital/core/env"
)

func main() {
	var dbURL = env.MustGet("DATABASE_URL")
	log.Println(dbURL)
}
Output:

func TryLoadDefault added in v0.5.3

func TryLoadDefault(paths ...string)

TryLoadDefault will attempt to load the default environment variables. This WILL NOT OVERRIDE an env variable that already exists. Those set prior to this call will remain. For env variables set in multiple files passed to this function, the FIRST one will prevail.

Example
package main

import (
	"github.com/LUSHDigital/core/env"
)

func main() {
	env.TryLoadDefault()
}
Output:

func TryOverloadDefault added in v0.19.0

func TryOverloadDefault(paths ...string)

TryOverloadDefault will attempt to load the default environment variables. This WILL OVERRIDE an env variable that already exists. Those set prior to this call will be replaced if set here. For env variables set in multiple files passed to this function, the LAST one will prevail.

Example
package main

import (
	"github.com/LUSHDigital/core/env"
)

func main() {
	env.TryOverloadDefault()
}
Output:

Types

This section is empty.

Jump to

Keyboard shortcuts

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