Skip to content

Fetching primitive values from env without hassle in Go!

License

Notifications You must be signed in to change notification settings

riandyrn/go-env

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.


About

Fetching primitive values from env without hassle in Go!

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages