Skip to content

Latest commit

 

History

History
57 lines (38 loc) · 1.55 KB

README.md

File metadata and controls

57 lines (38 loc) · 1.55 KB

Go Env

Build Status Go Report Card

Fetching primitive values from env without hassle in Go!

Why

Have you been annoyed when your code become ugly because you need to fetch value other than string from env but you also need to take care of its parsing error yet the only thing you need is just the value?

Here is an example of such situation when you are trying to fetch int value:

...
strVal := os.Getenv("IntKey")
intVal, _ := strconv.Atoi(strVal) // too much hassle!
...

This module is offering you solution to that!

intVal := env.GetInt("IntKey") // so simple!

Installation

go get github.com/riandyrn/go-env

Code Usage

...

import "github.com/riandyrn/go-env"

...
strVal := env.GetString("StrKey") // fetch string value
intVal := env.GetInt("IntKey") // fetch int value
boolVal := env.GetBool("BoolKey") // fetch bool value
secVal := env.GetSeconds("SecondsKey") // fetch duration value in seconds
strsVal := env.GetStrings("StringsKey") // fetch slice of strings value
...

No need to care that troublesome errors!

All errors in the process would simply make the functions return their returned type zero value (e.g env.GetInt("abc") would returns 0).

Check env_test.go to see possible scenarios handled by this module.

For full working example, check out /example directory.