Package dotenv
that supports importing data from files (eg .env
) to ENV
go get github.com/gookit/ini/v2/dotenv
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",
})
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")
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()
MIT