getenv

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: MPL-2.0 Imports: 8 Imported by: 21

README

getenv

English | 日本語

This is a package for getting environment variables with arbitrary types.

CircleCI

example

import (
	"fmt"
	"github.com/ieee0824/getenv"
	"time"
	"os"
)


fmt.Println(getenv.Duration("ANY_ENV"))
fmt.Println(getenv.Duration("ANY_ENV", 60))
fmt.Println(getenv.Duration("ANY_ENV","120s"))
fmt.Println(getenv.Duration("ANY_ENV", 60 * time.Second))
fmt.Println(getenv.Duration("ANY_ENV", "1h30m20s"))

os.Setenv("ANY_ENV", "60h")
fmt.Println(getenv.Duration("ANY_ENV"))
fmt.Println(getenv.Duration("ANY_ENV", 60))
fmt.Println(getenv.Duration("ANY_ENV","120s"))
fmt.Println(getenv.Duration("ANY_ENV", 60 * time.Second))
fmt.Println(getenv.Duration("ANY_ENV", "1h30m20s"))

os.Setenv("ANY_ENV", "60h")
fmt.Println(getenv.Duration("ANY_ENV"))
fmt.Println(getenv.Duration("ANY_ENV", 60))
fmt.Println(getenv.Duration("ANY_ENV","120s"))
fmt.Println(getenv.Duration("ANY_ENV", 60 * time.Second))
fmt.Println(getenv.Duration("ANY_ENV", "1h30m20s"))
0s
1m0s
2m0s
1m0s
1h30m20s
60h0m0s
60h0m0s
60h0m0s
60h0m0s
60h0m0s
18h12m16s
18h12m16s
18h12m16s
18h12m16s
18h12m16s

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Logger = &EnvLogger{
	w: os.Stdout,
}

Functions

func Bool

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

func Duration

func Duration(key string, def ...interface{}) time.Duration

func Int

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

func Int16

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

func Int32

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

func Int64

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

func String

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

func StringSlice added in v1.1.0

func StringSlice(key string, def ...[]string) []string

env format SOME_ENV=a,b,c,d,e,f

Types

type EnvLogger

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

func (*EnvLogger) Dump

func (l *EnvLogger) Dump(key string, def ...interface{})

func (*EnvLogger) SetWriter

func (l *EnvLogger) SetWriter(w io.Writer)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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