Skip to content

Latest commit

 

History

History
54 lines (38 loc) · 1.9 KB

README.md

File metadata and controls

54 lines (38 loc) · 1.9 KB

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")