dotenv

package
v2.2.3 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2024 License: MIT Imports: 6 Imported by: 3

README

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

Documentation

Overview

Package dotenv provide load .env data to os ENV

Index

Constants

This section is empty.

Variables

View Source
var (
	// UpperEnvKey change key to upper on set ENV
	UpperEnvKey = true

	// DefaultName default file name
	DefaultName = ".env"

	// OnlyLoadExists only load on file exists
	OnlyLoadExists bool
)

Functions

func Bool

func Bool(name string, defVal ...bool) (val bool)

Bool get a bool value by key

func ClearLoaded

func ClearLoaded()

ClearLoaded clear the previously set ENV value

func DontUpperEnvKey

func DontUpperEnvKey()

DontUpperEnvKey don't change key to upper on set ENV

func Get

func Get(name string, defVal ...string) (val string)

Get get os ENV value by name

func Int

func Int(name string, defVal ...int) (val int)

Int get a int value by key

func Load

func Load(dir string, filenames ...string) (err error)

Load parse .env file data to os ENV.

Usage:

dotenv.Load("./", ".env")

func LoadExistFiles added in v2.1.1

func LoadExistFiles(filePaths ...string) error

LoadExistFiles load ENV from given files, only load exists

func LoadExists

func LoadExists(dir string, filenames ...string) error

LoadExists only load on file exists

func LoadFiles added in v2.1.1

func LoadFiles(filePaths ...string) (err error)

LoadFiles load ENV from given file

func LoadFromMap

func LoadFromMap(kv map[string]string) (err error)

LoadFromMap load data from given string map

func LoadedData

func LoadedData() map[string]string

LoadedData get all loaded data by dontenv

func Reset added in v2.1.1

func Reset()

Reset clear the previously set ENV value

Types

This section is empty.

Jump to

Keyboard shortcuts

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