env

package module
v0.0.0-...-ccdc1a7 Latest Latest
Warning

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

Go to latest
Published: May 11, 2023 License: MIT Imports: 4 Imported by: 0

README

env

Under development.

Documentation

Overview

Package env can retrieve and parse environment variables, with defaults.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(key string, fallback bool) bool

Bool retrieves the value of the environment variable named by the key, parses the value as a boolean, and returns the result. If the variable is not present or its value cannot be parsed, fallback is returned.

func BoolVar

func BoolVar(p *bool, key string, fallback bool)

BoolVar retrieves the value of the environment variable named by the key, parses the value as a boolean, and stores the result into the variable pointed by p.

func Duration

func Duration(key string, fallback time.Duration) time.Duration

Duration retrieves the value of the environment variable named by the key, parses the value as time.Duration, and returns the result. If the variable is not present or its value cannot be parsed, fallback is returned.

func DurationVar

func DurationVar(p *time.Duration, key string, fallback time.Duration)

DurationVar retrieves the value of the environment variable named by the key, parses the value as time.Duration, and stores the result into the variable pointed by p.

func Float32

func Float32(key string, fallback float32) float32

Float32 retrieves the value of the environment variable named by the key, parses the value as a floating-point number, and returns the result. If the variable is not present or its value cannot be parsed, fallback is returned.

func Float32Var

func Float32Var(p *float32, key string, fallback float32)

Float32Var retrieves the value of the environment variable named by the key, parses the value as a floating-point number, and stores the result into the variable pointed by p.

func Float64

func Float64(key string, fallback float64) float64

Float64 retrieves the value of the environment variable named by the key, parses the value as a 64-bit floating-point number, and returns the result. If the variable is not present or its value cannot be parsed, fallback is returned.

func Float64Var

func Float64Var(p *float64, key string, fallback float64)

Float64Var retrieves the value of the environment variable named by the key, parses the value as a 64-bit floating-point number, and stores the result into the variable pointed by p.

func Int

func Int(key string, fallback int) int

Int retrieves the value of the environment variable named by the key, parses the value as an integer, and returns the result. If the variable is not present or its value cannot be parsed, fallback is returned.

func Int64

func Int64(key string, fallback int64) int64

Int64 retrieves the value of the environment variable named by the key, parses the value as a 64-bit integer, and returns the result. If the variable is not present or its value cannot be parsed, fallback is returned.

func Int64Var

func Int64Var(p *int64, key string, fallback int64)

Int64Var retrieves the value of the environment variable named by the key, parses the value as a 64-bit integer, and stores the result into the variable pointed by p.

func IntVar

func IntVar(p *int, key string, fallback int)

IntVar retrieves the value of the environment variable named by the key, parses the value as an integer, and stores the result into the variable pointed by p.

func Lookup

func Lookup(key string) (string, bool)

Lookup retrieves the value of the environment variable named by the key. If the variable is present in the environment the value is returned and the boolean is true. Otherwise, the returned value will be empty and the boolean will be false.

func Prefix

func Prefix() string

Prefix returns the prefix for the default VarSet.

func SetPrefix

func SetPrefix(prefix string)

SetPrefix makes this VarSet prepend the value of prefix to every key before it looks it up in the environment using String, StringVar, Bool, Int, et al. Use the empty string to reset.

func String

func String(key string, fallback string) string

String retrieves the value of the environment variable named by the key. If the variable is present in the environment, its value (which may be empty) is returned, otherwise fallback is returned.

func StringVar

func StringVar(p *string, key string, fallback string)

StringVar retrieves the value of the environment variable named by the key, and stores the result into the variable pointed by p.

func Uint

func Uint(key string, fallback uint) uint

Uint retrieves the value of the environment variable named by the key, parses the value as an unsigned integer, and returns the result. If the variable is not present or its value cannot be parsed, fallback is returned.

func Uint64

func Uint64(key string, fallback uint64) uint64

Uint64 retrieves the value of the environment variable named by the key, parses the value as an unsigned 64-bit integer, and returns the result. If the variable is not present or its value cannot be parsed, fallback is returned.

func Uint64Var

func Uint64Var(p *uint64, key string, fallback uint64)

Uint64Var retrieves the value of the environment variable named by the key, parses the value as an unsigned 64-bit integer, and stores the result into the variable pointed by p.

func UintVar

func UintVar(p *uint, key string, fallback uint)

UintVar retrieves the value of the environment variable named by the key, parses the value as an unsigned integer, and stores the result into the variable pointed by p.

Types

type VarSet

type VarSet struct {
	// contains filtered or unexported fields
}

VarSet represents a set of environment variables managed as key-value pairs.

func (*VarSet) Bool

func (vs *VarSet) Bool(key string, fallback bool) bool

Bool retrieves the value of the environment variable named by the key, parses the value as a boolean, and returns the result. If the variable is not present or its value cannot be parsed, fallback is returned.

func (*VarSet) Duration

func (vs *VarSet) Duration(key string, fallback time.Duration) time.Duration

Duration retrieves the value of the environment variable named by the key, parses the value as time.Duration, and returns the result. If the variable is not present or its value cannot be parsed, fallback is returned.

func (*VarSet) Float32

func (vs *VarSet) Float32(key string, fallback float32) float32

Float32 retrieves the value of the environment variable named by the key, parses the value as a floating-point number, and returns the result. If the variable is not present or its value cannot be parsed, fallback is returned.

func (*VarSet) Float64

func (vs *VarSet) Float64(key string, fallback float64) float64

Float64 retrieves the value of the environment variable named by the key, parses the value as a 64-bit floating-point number, and returns the result. If the variable is not present or its value cannot be parsed, fallback is returned.

func (*VarSet) Int

func (vs *VarSet) Int(key string, fallback int) int

Int retrieves the value of the environment variable named by the key, parses the value as an integer, and returns the result. If the variable is not present or its value cannot be parsed, fallback is returned.

func (*VarSet) Int64

func (vs *VarSet) Int64(key string, fallback int64) int64

Int64 retrieves the value of the environment variable named by the key, parses the value as a 64-bit integer, and returns the result. If the variable is not present or its value cannot be parsed, fallback is returned.

func (*VarSet) Lookup

func (vs *VarSet) Lookup(key string) (string, bool)

Lookup retrieves the value of the environment variable named by the key. If the variable is present in the environment the value is returned and the boolean is true. Otherwise, the returned value will be empty and the boolean will be false.

func (*VarSet) Prefix

func (vs *VarSet) Prefix() string

Prefix returns the prefix for this VarSet, if any.

func (*VarSet) SetPrefix

func (vs *VarSet) SetPrefix(prefix string)

SetPrefix makes this VarSet prepend the value of prefix to every key before it looks it up in the environment using String, StringVar, Bool, Int, et al. Use the empty string to reset.

func (*VarSet) String

func (vs *VarSet) String(key string, fallback string) string

String retrieves the value of the environment variable named by the key. If the variable is present in the environment, its value (which may be empty) is returned, otherwise fallback is returned.

func (*VarSet) Uint

func (vs *VarSet) Uint(key string, fallback uint) uint

Uint retrieves the value of the environment variable named by the key, parses the value as an unsigned integer, and returns the result. If the variable is not present or its value cannot be parsed, fallback is returned.

func (*VarSet) Uint64

func (vs *VarSet) Uint64(key string, fallback uint64) uint64

Uint64 retrieves the value of the environment variable named by the key, parses the value as an unsigned 64-bit integer, and returns the result. If the variable is not present or its value cannot be parsed, fallback is returned.

Jump to

Keyboard shortcuts

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