envar

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2021 License: MIT Imports: 5 Imported by: 1

README

envar

A simple wrapper of github.com/joho/godotenv, for methods to get typed environment variables. E.g. envar.Int("key"), envar.Bool("key"), or even envar.MilliSeconds("key").

Changelog

2021-06-01 Add GetDefs method so I can log it. (Why not just log it? Because user might want to fmt.Print it, or logger.Print it, to keep it simple, I choose to just return default key/value pairs.)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(key string) bool

Bool returns boolean value based on key.

func Float

func Float(key string) float64

Float returns float value based on key.

func Get

func Get(key string) interface{}

Get returns var from env based on key.

func GetDefs

func GetDefs() map[string]interface{}

GetDefs returns default key/value pairs.

func Int

func Int(key string) int

Int returns integer value based on key.

func Load

func Load(filenames ...string) (err error)

Load filenames, or .env if called by Load().

Notice existed env var won't be replaced by loading these files.

func MilliSeconds

func MilliSeconds(key string) time.Duration

MilliSeconds assumes key mapped to value of millisecond (e.g. 1000 for one second), and returns it as time.Duration type.

func SetDef

func SetDef(key string, value interface{})

SetDef set default value for key. When env var is not found, value set here is returned.

func String

func String(key string) string

String returns var from env based on key.

Types

This section is empty.

Jump to

Keyboard shortcuts

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