osenv

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2020 License: MIT Imports: 3 Imported by: 3

README

Extensional OS environment variables helper for Go.

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(key string, fallback ...string) string

Get returns the environment variable associated with the given key. Returns the fallback value if not exists.

func GetInt added in v0.3.0

func GetInt(key string, fallback ...int) (int, error)

GetInt converts the environment variable associated with the given key to int and returns it. Returns the fallback value if the key is not exists or the value is invalid.

func MustGet added in v0.2.0

func MustGet(key string) string

MustGet returns the environment variable associated with the given key, and panics if the key is not exists.

func MustGetInt added in v0.3.0

func MustGetInt(key string) int

MustGetInt converts the environment variable associated with the given key to int and returns it. Panics if the key is not exists or the value is invalid.

func SetNX

func SetNX(key, value string) error

SetNX sets the value of the environment variable named by the key if not exist.

Types

This section is empty.

Jump to

Keyboard shortcuts

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