envar

package module
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: MIT Imports: 9 Imported by: 19

README

envar

test A simple library that handles environment variables

simplest way

var host = envar.String("DB_HOST")
var port = envar.Int("DB_PORT")
var debug = envar.Bool("DEBUG")

default value

var host = envar.Get("DB_HOST").String("localhost")
var port = envar.Get("DB_PORT").Int(3306)
var debug = envar.Get("DEBUG").Bool(true)

multiple environment variables

Specify multiple environment variables and adopt the one whose value is set.

var primaryHost = envar.Get("PRIMARY_HOST", "DB_HOST").String("localhost")
var primaryPort = envar.Get("PRIMARY_PORT", "DB_PORT").Int(3306)
var replicaHost = envar.Get("REPLICA_HOST", "DB_HOST").String("localhost")
var replicaPort = envar.Get("REPLICA_PORT", "DB_PORT").Int(3306)

bind

type Example struct {
	Host string `envar:"PRIMARY_HOST,DB_HOST;default=localhost"`
	Port int `envar:"PRIMARY_PORT,DB_PORT;default=3306"`
	Debug bool `envar:"DEBUG"`
}
obj := &Example{}
envar.Bind(&obj, false)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bind

func Bind(value interface{}, validation ...bool) error

func Bool

func Bool(names ...string) bool

func BoolP added in v0.2.2

func BoolP(names ...string) *bool

func Complex128

func Complex128(names ...string) complex128

func Complex128P added in v0.2.2

func Complex128P(names ...string) *complex128

func Complex128Slice

func Complex128Slice(names ...string) []complex128

func Complex64

func Complex64(names ...string) complex64

func Complex64P added in v0.2.2

func Complex64P(names ...string) *complex64

func Complex64Slice

func Complex64Slice(names ...string) []complex64

func Duration

func Duration(names ...string) time.Duration

func Float32

func Float32(names ...string) float32

func Float32P added in v0.2.2

func Float32P(names ...string) *float32

func Float32Slice

func Float32Slice(names ...string) []float32

func Float64

func Float64(names ...string) float64

func Float64P added in v0.2.2

func Float64P(names ...string) *float64

func Float64Slice

func Float64Slice(names ...string) []float64

func GetHostname

func GetHostname(defaultName string) string

func Has

func Has(names ...string) bool

func Int

func Int(names ...string) int

func Int16

func Int16(names ...string) int16

func Int16P added in v0.2.2

func Int16P(names ...string) *int16

func Int16Slice

func Int16Slice(names ...string) []int16

func Int32

func Int32(names ...string) int32

func Int32P added in v0.2.2

func Int32P(names ...string) *int32

func Int32Slice

func Int32Slice(names ...string) []int32

func Int64

func Int64(names ...string) int64

func Int64P added in v0.2.2

func Int64P(names ...string) *int64

func Int64Slice

func Int64Slice(names ...string) []int64

func Int8

func Int8(names ...string) int8

func Int8P added in v0.2.2

func Int8P(names ...string) *int8

func Int8Slice

func Int8Slice(names ...string) []int8

func IntP added in v0.2.2

func IntP(names ...string) *int

func IntSlice

func IntSlice(names ...string) []int

func Load added in v0.2.2

func Load(filenames ...string) error

func Reader

func Reader(names ...string) *os.File

func SetValidator

func SetValidator(validator *validator.Validate)

func Split

func Split(names ...string) []string

func String

func String(names ...string) string

func StringP added in v0.2.2

func StringP(names ...string) *string

func ToLower

func ToLower(names ...string) string

func ToUpper

func ToUpper(names ...string) string

func Uint

func Uint(names ...string) uint

func Uint16

func Uint16(names ...string) uint16

func Uint16P added in v0.2.2

func Uint16P(names ...string) *uint16

func Uint16Slice

func Uint16Slice(names ...string) []uint16

func Uint32

func Uint32(names ...string) uint32

func Uint32P added in v0.2.2

func Uint32P(names ...string) *uint32

func Uint32Slice

func Uint32Slice(names ...string) []uint32

func Uint64

func Uint64(names ...string) uint64

func Uint64P added in v0.2.2

func Uint64P(names ...string) *uint64

func Uint64Slice

func Uint64Slice(names ...string) []uint64

func Uint8

func Uint8(names ...string) uint8

func Uint8P added in v0.2.2

func Uint8P(names ...string) *uint8

func Uint8Slice

func Uint8Slice(names ...string) []uint8

func UintP added in v0.2.2

func UintP(names ...string) *uint

func UintSlice

func UintSlice(names ...string) []uint

func Writer

func Writer(names ...string) *os.File

Types

type Bytes

type Bytes []byte

type Env

type Env struct {
	Name string
	// contains filtered or unexported fields
}

func Get

func Get(names ...string) Env

func (Env) Bool

func (e Env) Bool(defaultValue bool) bool

func (Env) BoolP added in v0.2.2

func (e Env) BoolP(defaultValue bool) *bool

func (Env) ByteSlice

func (e Env) ByteSlice(defaultValue []byte, sep string) []byte

func (Env) Bytes

func (e Env) Bytes(defaultValue string) []byte

func (Env) Complex128

func (e Env) Complex128(defaultValue complex128) complex128

func (Env) Complex128P added in v0.2.2

func (e Env) Complex128P(defaultValue complex128) *complex128

func (Env) Complex128Slice

func (e Env) Complex128Slice(defaultValue []complex128, sep string) []complex128

func (Env) Complex64

func (e Env) Complex64(defaultValue complex64) complex64

func (Env) Complex64P added in v0.2.2

func (e Env) Complex64P(defaultValue complex64) *complex64

func (Env) Complex64Slice

func (e Env) Complex64Slice(defaultValue []complex64, sep string) []complex64

func (Env) Duration

func (e Env) Duration(defaultValue time.Duration) time.Duration

func (Env) Float32

func (e Env) Float32(defaultValue float32) float32

func (Env) Float32P added in v0.2.2

func (e Env) Float32P(defaultValue float32) *float32

func (Env) Float32Slice

func (e Env) Float32Slice(defaultValue []float32, sep string) []float32

func (Env) Float64

func (e Env) Float64(defaultValue float64) float64

func (Env) Float64P added in v0.2.2

func (e Env) Float64P(defaultValue float64) *float64

func (Env) Float64Slice

func (e Env) Float64Slice(defaultValue []float64, sep string) []float64

func (Env) Has

func (e Env) Has() bool

func (Env) Int

func (e Env) Int(defaultValue int) int

func (Env) Int16

func (e Env) Int16(defaultValue int16) int16

func (Env) Int16P added in v0.2.2

func (e Env) Int16P(defaultValue int16) *int16

func (Env) Int16Slice

func (e Env) Int16Slice(defaultValue []int16, sep string) []int16

func (Env) Int32

func (e Env) Int32(defaultValue int32) int32

func (Env) Int32P added in v0.2.2

func (e Env) Int32P(defaultValue int32) *int32

func (Env) Int32Slice

func (e Env) Int32Slice(defaultValue []int32, sep string) []int32

func (Env) Int64

func (e Env) Int64(defaultValue int64) int64

func (Env) Int64P added in v0.2.2

func (e Env) Int64P(defaultValue int64) *int64

func (Env) Int64Slice

func (e Env) Int64Slice(defaultValue []int64, sep string) []int64

func (Env) Int8

func (e Env) Int8(defaultValue int8) int8

func (Env) Int8P added in v0.2.2

func (e Env) Int8P(defaultValue int8) *int8

func (Env) Int8Slice

func (e Env) Int8Slice(defaultValue []int8, sep string) []int8

func (Env) IntP added in v0.2.2

func (e Env) IntP(defaultValue int) *int

func (Env) IntSlice

func (e Env) IntSlice(defaultValue []int, sep string) []int

func (Env) Reader

func (e Env) Reader(defaultValue string) *os.File

func (Env) Split

func (e Env) Split(defaultValue, sep string) []string

func (Env) String

func (e Env) String(defaultValue string) string

func (Env) StringP added in v0.2.2

func (e Env) StringP(defaultValue string) *string

func (Env) ToLower

func (e Env) ToLower(defaultValue string) string

func (Env) ToUpper

func (e Env) ToUpper(defaultValue string) string

func (Env) Uint

func (e Env) Uint(defaultValue uint) uint

func (Env) Uint16

func (e Env) Uint16(defaultValue uint16) uint16

func (Env) Uint16P added in v0.2.2

func (e Env) Uint16P(defaultValue uint16) *uint16

func (Env) Uint16Slice

func (e Env) Uint16Slice(defaultValue []uint16, sep string) []uint16

func (Env) Uint32

func (e Env) Uint32(defaultValue uint32) uint32

func (Env) Uint32P added in v0.2.2

func (e Env) Uint32P(defaultValue uint32) *uint32

func (Env) Uint32Slice

func (e Env) Uint32Slice(defaultValue []uint32, sep string) []uint32

func (Env) Uint64

func (e Env) Uint64(defaultValue uint64) uint64

func (Env) Uint64P added in v0.2.2

func (e Env) Uint64P(defaultValue uint64) *uint64

func (Env) Uint64Slice

func (e Env) Uint64Slice(defaultValue []uint64, sep string) []uint64

func (Env) Uint8

func (e Env) Uint8(defaultValue uint8) uint8

func (Env) Uint8P added in v0.2.2

func (e Env) Uint8P(defaultValue uint8) *uint8

func (Env) Uint8Slice

func (e Env) Uint8Slice(defaultValue []uint8, sep string) []uint8

func (Env) UintP added in v0.2.2

func (e Env) UintP(defaultValue uint) *uint

func (Env) UintSlice

func (e Env) UintSlice(defaultValue []uint, sep string) []uint

func (Env) Writer

func (e Env) Writer(defaultValue string) *os.File

type Ref

type Ref struct {
	Name string
	// contains filtered or unexported fields
}

func Late

func Late(names ...string) Ref

func (Ref) Bool

func (ref Ref) Bool(v *bool) bool

func (Ref) Complex128

func (ref Ref) Complex128(v *complex128) complex128

func (Ref) Complex64

func (ref Ref) Complex64(v *complex64) complex64

func (Ref) Duration

func (ref Ref) Duration(v time.Duration) time.Duration

func (Ref) Float32

func (ref Ref) Float32(v *float32) float32

func (Ref) Float64

func (ref Ref) Float64(v *float64) float64

func (Ref) Has

func (ref Ref) Has() bool

func (Ref) Int

func (ref Ref) Int(v *int) int

func (Ref) Int16

func (ref Ref) Int16(v *int16) int16

func (Ref) Int32

func (ref Ref) Int32(v *int32) int32

func (Ref) Int64

func (ref Ref) Int64(v *int64) int64

func (Ref) Int8

func (ref Ref) Int8(v *int8) int8

func (Ref) String

func (ref Ref) String(v string) string

func (Ref) Uint

func (ref Ref) Uint(v *uint) uint

func (Ref) Uint16

func (ref Ref) Uint16(v *uint16) uint16

func (Ref) Uint32

func (ref Ref) Uint32(v *uint32) uint32

func (Ref) Uint64

func (ref Ref) Uint64(v *uint64) uint64

func (Ref) Uint8

func (ref Ref) Uint8(v *uint8) uint8

Directories

Path Synopsis
pkg
env
log

Jump to

Keyboard shortcuts

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