Help us shape the future of Go! Take the 2026 Go Developer Survey

defenv

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2017 License: MIT Imports: 3 Imported by: 0

README

DefEnv

GoDoc Build Status

DefEnv is a go package that contains methods for extracting environment variables and converting them to specified types. If there is no environment variable, the default value is used.

There are two types of methods in a package: ordinary and strict. If there is no environment variable, or if a parsing error occurs, ordinary methods return a default value.

value := defenv.Int("WORKER_NUMBER", 8)

Unlike ordinary methods, strict methods return an error when parsing fails.

value, err := defenv.IntStrict("WORKER_NUMBER", 8)

Methods:

Type Ordinary Strict
bool Bool BoolStrict
time.Duration Duration DurationStrict
float64 Float64 Float64Strict
int Int IntStrict
int64 Int64 Int64Strict
string String -
uint Uint UintStrict
uint64 Uint64 Uint64Strict

Docs

See package documentation at https://godoc.org/github.com/reinventer/defenv

Documentation

Overview

Package defenv contains methods for extracting environments variables.

There are two types of methods in a package: ordinary and strict. If there is no environment variable, or if a parsing error occurs, ordinary methods return a default value.

value := defenv.Int("WORKER_NUMBER", 8)

Unlike ordinary methods, strict methods return an error when parsing fails.

value, err := defenv.IntStrict("WORKER_NUMBER", 8)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(name string, defaultValue bool) bool

Bool extracts bool value from environment variable named name and returns defaultValue if it is absent or can not be parsed

func BoolStrict

func BoolStrict(name string, defaultValue bool) (bool, error)

BoolStrict extracts bool value from environment variable named name and returns defaultValue if it is absent. If the environment variable can not be parsed, the method returns an error

func Duration

func Duration(name string, defaultValue time.Duration) time.Duration

Duration extracts time.Duration value from environment variable named name and returns defaultValue if it is absent or can not be parsed

func DurationStrict

func DurationStrict(name string, defaultValue time.Duration) (time.Duration, error)

DurationStrict extracts time.Duration value from environment variable named name and returns defaultValue if it is absent. If the environment variable can not be parsed, the method returns an error

func Float64

func Float64(name string, defaultValue float64) float64

Float64 extracts float64 value from environment variable named name and returns defaultValue if it is absent or can not be parsed

func Float64Strict

func Float64Strict(name string, defaultValue float64) (float64, error)

Float64Strict extracts float64 value from environment variable named name and returns defaultValue if it is absent. If the environment variable can not be parsed, the method returns an error

func Int

func Int(name string, defaultValue int) int

Int extracts int value from environment variable named name and returns defaultValue if it is absent or can not be parsed

func Int64

func Int64(name string, defaultValue int64) int64

Int64 extracts int64 value from environment variable named name and returns defaultValue if it is absent or can not be parsed

func Int64Strict

func Int64Strict(name string, defaultValue int64) (int64, error)

Int64Strict extracts int64 value from environment variable named name and returns defaultValue if it is absent. If the environment variable can not be parsed, the method returns an error

func IntStrict

func IntStrict(name string, defaultValue int) (int, error)

IntStrict extracts int value from environment variable named name and returns defaultValue if it is absent. If the environment variable can not be parsed, the method returns an error

func String

func String(name, defaultValue string) string

String extracts string value from environment variable named name and returns defaultValue if it is absent or can not be parsed

func Uint

func Uint(name string, defaultValue uint) uint

Uint extracts uint value from environment variable named name and returns defaultValue if it is absent or can not be parsed

func Uint64

func Uint64(name string, defaultValue uint64) uint64

Uint64 extracts uint64 value from environment variable named name and returns defaultValue if it is absent or can not be parsed

func Uint64Strict

func Uint64Strict(name string, defaultValue uint64) (uint64, error)

Uint64Strict extracts uint64 value from environment variable named name and returns defaultValue if it is absent. If the environment variable can not be parsed, the method returns an error

func UintStrict

func UintStrict(name string, defaultValue uint) (uint, error)

UintStrict extracts uint value from environment variable named name and returns defaultValue if it is absent. If the environment variable can not be parsed, the method returns an error

Types

This section is empty.

Jump to

Keyboard shortcuts

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