项目作者: riandyrn

项目描述 :
Fetching primitive values from env without hassle in Go!
高级语言: Go
项目地址: git://github.com/riandyrn/go-env.git
创建时间: 2019-06-15T22:19:17Z
项目社区:https://github.com/riandyrn/go-env

开源协议:MIT License

下载


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:

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

This module is offering you solution to that!

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

Installation

  1. go get github.com/riandyrn/go-env

Code Usage

  1. ...
  2. import "github.com/riandyrn/go-env"
  3. ...
  4. strVal := env.GetString("StrKey") // fetch string value
  5. intVal := env.GetInt("IntKey") // fetch int value
  6. boolVal := env.GetBool("BoolKey") // fetch bool value
  7. secVal := env.GetSeconds("SecondsKey") // fetch duration value in seconds
  8. strsVal := env.GetStrings("StringsKey") // fetch slice of strings value
  9. ...

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.