Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

Dotenv

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

  • filename support simple glob pattern. eg: .env.*, *.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 DontUpperEnvKey()
// get env value
func Bool(name string, defVal ...bool) (val bool)
func Get(name string, defVal ...string) (val string)
func Int(name string, defVal ...int) (val int)
// load env files/data
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)
// extra methods
func ClearLoaded()
func LoadedFiles() []string
func LoadedData() map[string]string
func Reset()

License

MIT