Skip to content

Latest commit

 

History

History

dotenv

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Dotenv

Package dotenv that supports importing data from files (eg .env) to ENV

Install

go get github.com/gookit/ini/v2/dotenv

Usage

Load Env

err := dotenv.Load("./", ".env")
// Or use
// err := dotenv.LoadExists("./", ".env")

Load from string-map:

err := dotenv.LoadFromMap(map[string]string{
	"ENV_KEY": "value",
	"LOG_LEVEL": "info",
})

Read Env

val := dotenv.Get("ENV_KEY")
// Or use 
// val := os.Getenv("ENV_KEY")

// get int value
intVal := dotenv.Int("LOG_LEVEL")

// get bool value
blVal := dotenv.Bool("OPEN_DEBUG")

// with default value
val := dotenv.Get("ENV_KEY", "default value")

Functions API

func Bool(name string, defVal ...bool) (val bool)
func ClearLoaded()
func DontUpperEnvKey()
func Get(name string, defVal ...string) (val string)
func Int(name string, defVal ...int) (val int)
func Load(dir string, filenames ...string) (err error)
func LoadExistFiles(filePaths ...string) error
func LoadExists(dir string, filenames ...string) error
func LoadFiles(filePaths ...string) (err error)
func LoadFromMap(kv map[string]string) (err error)
func LoadedData() map[string]string
func Reset()

License

MIT