env

package module
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2023 License: MIT Imports: 1 Imported by: 9

README

Env Package Documentation

Problem Statement

The native Go library, os, retrieves environment variables with a default type of string. The env package addresses this limitation by providing a solution for retrieving environment variables in multiple data types. Additionally, it offers functionality for setting default values and checking the presence of required environment variables.

Installation

To integrate the env package into your Go project, use the following go get command:

go get -u github.com/metadiv-io/env

Supported Types

The env package supports the following data types for environment variable retrieval:

  • string
  • int
  • int64
  • int32
  • int16
  • int8
  • float64
  • float32
  • uint
  • uint64
  • uint32
  • uint16
  • uint8
  • bool
  • complex128
  • complex64

Usage

package main

import (
	"fmt"
	"github.com/metadiv-io/env"
)

func main() {
	// Retrieve a string variable with a default value
	v := env.String("STRING_VAR", "default")

	// Retrieve a string variable and panic if not set
	v1 := env.MustString("STRING_VAR")

	// Retrieve a list of string variables with a default value
	vs := env.Strings("STRING_VARS", []string{"default"})

	// Retrieve a list of string variables and panic if not set
	vs1 := env.MustStrings("STRING_VARS")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(key string, defaultValue ...bool) bool

Bool returns the value of the environment variable named by the key.

func Bools

func Bools(key string, defaultValue ...[]bool) []bool

Bools returns the list of values of the environment variable named by the key.

func Complex128

func Complex128(key string, defaultValue ...complex128) complex128

Complex128 returns the value of the environment variable named by the key.

func Complex128s

func Complex128s(key string, defaultValue ...[]complex128) []complex128

Complex128s returns the list of values of the environment variable named by the key.

func Complex64

func Complex64(key string, defaultValue ...complex64) complex64

Complex64 returns the value of the environment variable named by the key.

func Complex64s

func Complex64s(key string, defaultValue ...[]complex64) []complex64

Complex64s returns the list of values of the environment variable named by the key.

func Float32

func Float32(key string, defaultValue ...float32) float32

Float32 returns the value of the environment variable named by the key.

func Float32s

func Float32s(key string, defaultValue ...[]float32) []float32

Float32s returns the list of values of the environment variable named by the key.

func Float64

func Float64(key string, defaultValue ...float64) float64

Float64 returns the value of the environment variable named by the key.

func Float64s

func Float64s(key string, defaultValue ...[]float64) []float64

Float64s returns the list of values of the environment variable named by the key.

func Int

func Int(key string, defaultValue ...int) int

Int returns the value of the environment variable named by the key.

func Int16

func Int16(key string, defaultValue ...int16) int16

Int16 returns the value of the environment variable named by the key.

func Int16s

func Int16s(key string, defaultValue ...[]int16) []int16

Int16s returns the list of values of the environment variable named by the key.

func Int32

func Int32(key string, defaultValue ...int32) int32

Int32 returns the value of the environment variable named by the key.

func Int32s

func Int32s(key string, defaultValue ...[]int32) []int32

Int32s returns the value of the environment variable named by the key.

func Int64

func Int64(key string, defaultValue ...int64) int64

Int64 returns the value of the environment variable named by the key.

func Int64s

func Int64s(key string, defaultValue ...[]int64) []int64

Int64s returns the list of values of the environment variable named by the key.

func Int8

func Int8(key string, defaultValue ...int8) int8

Int8 returns the value of the environment variable named by the key.

func Int8s

func Int8s(key string, defaultValue ...[]int8) []int8

Int8s returns the list of values of the environment variable named by the key.

func Ints

func Ints(key string, defaultValue ...[]int) []int

Ints returns the list of values of the environment variable named by the key.

func MustBool

func MustBool(key string) bool

MustBool returns the value of the environment variable named by the key. It panics if the value is empty.

func MustBools

func MustBools(key string) []bool

MustBools returns the list of values of the environment variable named by the key. It panics if the value is empty.

func MustComplex128

func MustComplex128(key string) complex128

MustComplex128 returns the value of the environment variable named by the key. It panics if the value is empty.

func MustComplex128s

func MustComplex128s(key string) []complex128

MustComplex128s returns the list of values of the environment variable named by the key. It panics if the value is empty.

func MustComplex64

func MustComplex64(key string) complex64

MustComplex64 returns the value of the environment variable named by the key. It panics if the value is empty.

func MustComplex64s

func MustComplex64s(key string) []complex64

MustComplex64s returns the list of values of the environment variable named by the key. It panics if the value is empty.

func MustFloat32

func MustFloat32(key string) float32

MustFloat32 returns the value of the environment variable named by the key. It panics if the value is empty.

func MustFloat32s

func MustFloat32s(key string) []float32

MustFloat32s returns the list of values of the environment variable named by the key. It panics if the value is empty.

func MustFloat64

func MustFloat64(key string) float64

MustFloat64 returns the value of the environment variable named by the key. It panics if the value is empty.

func MustFloat64s

func MustFloat64s(key string) []float64

MustFloat64s returns the list of values of the environment variable named by the key. It panics if the value is empty.

func MustInt

func MustInt(key string) int

MustInt returns the value of the environment variable named by the key. It panics if the value is empty.

func MustInt16

func MustInt16(key string) int16

MustInt16 returns the value of the environment variable named by the key. It panics if the value is empty.

func MustInt16s

func MustInt16s(key string) []int16

MustInt16s returns the list of values of the environment variable named by the key. It panics if the value is empty.

func MustInt32

func MustInt32(key string) int32

MustInt32 returns the value of the environment variable named by the key. If the value is empty, it will panic.

func MustInt32s

func MustInt32s(key string) []int32

MustInt32s returns the value of the environment variable named by the key. If the value is empty, it will panic.

func MustInt64

func MustInt64(key string) int64

MustInt64 returns the value of the environment variable named by the key. It panics if the value is empty.

func MustInt64s

func MustInt64s(key string) []int64

MustInt64s returns the list of values of the environment variable named by the key. It panics if the value is empty.

func MustInt8

func MustInt8(key string) int8

MustInt8 returns the value of the environment variable named by the key. It panics if the value is empty.

func MustInt8s

func MustInt8s(key string) []int8

MustInt8s returns the list of values of the environment variable named by the key. It panics if the value is empty.

func MustInts

func MustInts(key string) []int

MustInts returns the list of values of the environment variable named by the key. It panics if the value is empty.

func MustString

func MustString(key string) string

MustString returns the value of the environment variable named by the key. It panics if the value is empty.

func MustStrings

func MustStrings(key string) []string

MustStrings returns the list of values of the environment variable named by the key. It panics if the value is empty.

func MustUint

func MustUint(key string) uint

MustUint returns the value of the environment variable named by the key. It panics if the value is empty.

func MustUint16

func MustUint16(key string) uint16

MustUint16 returns the value of the environment variable named by the key. It panics if the value is empty.

func MustUint16s

func MustUint16s(key string) []uint16

MustUint16s returns the list of values of the environment variable named by the key. It panics if the value is empty.

func MustUint32

func MustUint32(key string) uint32

MustUint32 returns the value of the environment variable named by the key. It panics if the value is empty.

func MustUint32s

func MustUint32s(key string) []uint32

MustUint32s returns the list of values of the environment variable named by the key. It panics if the value is empty.

func MustUint64

func MustUint64(key string) uint64

MustUint64 returns the value of the environment variable named by the key. It panics if the value is empty.

func MustUint64s

func MustUint64s(key string) []uint64

MustUint64s returns the list of values of the environment variable named by the key. It panics if the value is empty.

func MustUint8

func MustUint8(key string) uint8

MustUint8 returns the value of the environment variable named by the key. It panics if the value is empty.

func MustUint8s

func MustUint8s(key string) []uint8

MustUint8s returns the list of values of the environment variable named by the key. It panics if the value is empty.

func MustUints

func MustUints(key string) []uint

MustUints returns the list of values of the environment variable named by the key. It panics if the value is empty.

func String

func String(key string, defaultValue ...string) string

String returns the value of the environment variable named by the key.

func Strings

func Strings(key string, defaultValue ...[]string) []string

Strings returns the list of values of the environment variable named by the key.

func Uint

func Uint(key string, defaultValue ...uint) uint

Uint returns the value of the environment variable named by the key.

func Uint16

func Uint16(key string, defaultValue ...uint16) uint16

Uint16 returns the value of the environment variable named by the key.

func Uint16s

func Uint16s(key string, defaultValue ...[]uint16) []uint16

Uint16s returns the list of values of the environment variable named by the key.

func Uint32

func Uint32(key string, defaultValue ...uint32) uint32

Uint32 returns the value of the environment variable named by the key.

func Uint32s

func Uint32s(key string, defaultValue ...[]uint32) []uint32

Uint32s returns the list of values of the environment variable named by the key.

func Uint64

func Uint64(key string, defaultValue ...uint64) uint64

Uint64 returns the value of the environment variable named by the key.

func Uint64s

func Uint64s(key string, defaultValue ...[]uint64) []uint64

Uint64s returns the list of values of the environment variable named by the key.

func Uint8

func Uint8(key string, defaultValue ...uint8) uint8

Uint8 returns the value of the environment variable named by the key.

func Uint8s

func Uint8s(key string, defaultValue ...[]uint8) []uint8

Uint8s returns the list of values of the environment variable named by the key.

func Uints

func Uints(key string, defaultValue ...[]uint) []uint

Uints returns the list of values of the environment variable named by the key.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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