Documentation ¶
Index ¶
- Variables
- func AllowEmptyEnv(allowEmptyEnvVars bool)
- func CheckFileExists(filename string) bool
- func Get(key string) interface{}
- func GetBool(key string) bool
- func GetDuration(key string) time.Duration
- func GetFloat64(key string) float64
- func GetFromFile(filePath, key, separator string) (interface{}, bool, error)
- func GetInt(key string) int
- func GetInt32(key string) int32
- func GetInt64(key string) int64
- func GetIntSlice(key string) []int
- func GetPrefix() string
- func GetSizeInBytes(key string) uint
- func GetString(key string) string
- func GetStringMap(key string) map[string]interface{}
- func GetStringMapString(key string) map[string]string
- func GetStringMapStringSlice(key string) map[string][]string
- func GetStringSlice(key string) []string
- func GetTime(key string) time.Time
- func GetUint(key string) uint
- func GetUint32(key string) uint32
- func GetUint64(key string) uint64
- func InvalidateEnvCacheForFile(filePath string)
- func IsSet(key string) bool
- func LoadConfig() error
- func LookUp(key string) (interface{}, bool)
- func Save() error
- func Set(key, value string)
- func SetConfigFile(configFile string)
- func SetPrefix(prefix string)
- func Write(key string, value interface{}) error
- func WriteFile(filename string, data []byte, perm os.FileMode) error
- type DotEnv
- func (e *DotEnv) AllowEmptyEnvVars(allowEmptyEnvVars bool)
- func (e *DotEnv) Get(key string) interface{}
- func (e *DotEnv) GetBool(key string) bool
- func (e *DotEnv) GetDuration(key string) time.Duration
- func (e *DotEnv) GetFloat64(key string) float64
- func (e *DotEnv) GetInt(key string) int
- func (e *DotEnv) GetInt32(key string) int32
- func (e *DotEnv) GetInt64(key string) int64
- func (e *DotEnv) GetIntSlice(key string) []int
- func (e *DotEnv) GetPrefix() string
- func (e *DotEnv) GetSizeInBytes(key string) uint
- func (e *DotEnv) GetString(key string) string
- func (e *DotEnv) GetStringMap(key string) map[string]interface{}
- func (e *DotEnv) GetStringMapString(key string) map[string]string
- func (e *DotEnv) GetStringMapStringSlice(key string) map[string][]string
- func (e *DotEnv) GetStringSlice(key string) []string
- func (e *DotEnv) GetTime(key string) time.Time
- func (e *DotEnv) GetUint(key string) uint
- func (e *DotEnv) GetUint32(key string) uint32
- func (e *DotEnv) GetUint64(key string) uint64
- func (e *DotEnv) IsSet(key string) bool
- func (e *DotEnv) LoadConfig() (err error)
- func (e *DotEnv) LookUp(key string) (interface{}, bool)
- func (e *DotEnv) Save() error
- func (e *DotEnv) Set(key string, value interface{})
- func (e *DotEnv) SetConfigFile(configFile string)
- func (e *DotEnv) SetPrefix(prefix string)
- func (e *DotEnv) Write(key string, value interface{}) error
Constants ¶
This section is empty.
Variables ¶
var ( DefaultConfigFile = ".env" DefaultSeparator = "=" )
Functions ¶
func AllowEmptyEnv ¶
func AllowEmptyEnv(allowEmptyEnvVars bool)
AllowEmptyEnv tells Dotenv to consider set, but empty environment variables as valid values instead of falling back to config value. This is set to true by default.
func CheckFileExists ¶
CheckFileExists returns true if a file exists and is not a directory.
func Get ¶
func Get(key string) interface{}
Get can retrieve any value given the key to use. Get is case-insensitive for a key. Dotenv will check in the following order: configOverride cache, env, key/value store, config file
Get returns an interface. For a specific value use one of the Get___ methods e.g. GetBool(key) for a boolean value
func GetDuration ¶
GetDuration returns the value associated with the key as a duration.
func GetFloat64 ¶
GetFloat64 returns the value associated with the key as a float64.
func GetFromFile ¶
GetFromFile retrieves the value of the config variable named by the key from the config file If the variable is present in the environment the value (which may be empty) is returned and the boolean is true. Otherwise the returned value will be empty and the boolean will be false.
func GetIntSlice ¶
GetIntSlice returns the value associated with the key as a slice of int values.
func GetPrefix ¶
func GetPrefix() string
GetPrefix returns the prefix that ENVIRONMENT variables will use which is set with SetPrefix.
func GetSizeInBytes ¶
GetSizeInBytes returns the size of the value associated with the given key in bytes.
func GetStringMap ¶
GetStringMap returns the value associated with the key as a map of interfaces.
func GetStringMapString ¶
GetStringMapString returns the value associated with the key as a map of strings.
func GetStringMapStringSlice ¶
GetStringMapStringSlice returns the value associated with the key as a map to a slice of strings.
func GetStringSlice ¶
GetStringSlice returns the value associated with the key as a slice of strings.
func InvalidateEnvCacheForFile ¶
func InvalidateEnvCacheForFile(filePath string)
InvalidateEnvCacheForFile invalidates the cached content of a file
func IsSet ¶
IsSet checks to see if the key has been set in any of the env var, config cache or config file. IsSet is case-insensitive for a key.
func LoadConfig ¶
func LoadConfig() error
LoadConfig finds and read the config file. returns os.ErrNotExist if config file does not exist
func LookUp ¶
LookUp retrieves the value of the configuration named by the key. If the variable is present in the configuration file the value (which may be empty) is returned and the boolean is true. Otherwise the returned value will be empty and the boolean will be false.
func Set ¶
func Set(key, value string)
Set sets or update env variable This will be used instead of following the normal precedence when getting the value
func SetConfigFile ¶
func SetConfigFile(configFile string)
SetConfigFile explicitly defines the path, name and extension of the config file. Dotenv will use this and not check .env from the current directory.
func SetPrefix ¶
func SetPrefix(prefix string)
SetPrefix defines a prefix that ENVIRONMENT variables will use. E.g. if your prefix is "pro", the env registry will look for env variables that start with "PRO_".
Types ¶
type DotEnv ¶
type DotEnv struct { ConfigFile string // Separator is the symbol that separates a the key-value pair. // Default is `=` Separator string Config map[string]interface{} // contains filtered or unexported fields }
DotEnv is a config registry
func Init ¶
Init returns an initialized DotEnv instance.. Call this function as close as possible to the start of your program (ideally in main where your config file resides) If you call Init without any args it will default to loading .env in the current path You can otherwise tell it which file to load like
dotenv.Init("file.env")