/osenv

An extensional OS environment variables helper for Go

Primary LanguageGoMIT LicenseMIT

Extensional OS environment variables helper for Go.

Build Status Coverage Status Go.Dev reference Go Report Card Release Downloads Chat Community

Usage

$ go get -u clevergo.tech/osenv

Get

Gets the environment variable associated with the given key, a fallback(default) value will be returned if not exist.

Assume environment is that FOO=BAR EMPTY=.

Method Value
osenv.Get("FOO") BAR
osenv.Get("EMPTY") -
osenv.Get("EMPTY", "BUZZ") -
osenv.Get("FIZZ") -
osenv.Get("FIZZ", "BUZZ") BUZZ

Similar functions:

  • GetInt

MustGet

Gets the environment variable associated with the given key, and panics if not exist.

osenv.MustGet("FOO") // BAR
osenv.MustGet("NIL") // panics

Similar functions:

  • MustGetInt

SetNX

Sets an environment variable if not exist.

osenv.SetNX("NONEXISTENT", "VALUE")