Documentation ¶
Overview ¶
Package env provides a uniform way of dealing with environment such as .env files, os.Environ and (command line) flags. The goal is, that applications don't have to care about the source from a variable but just handle the values.
Index ¶
- func LoadDotenv() map[string]any
- func ParseFlags(args []string) map[string]any
- type Env
- func (env Env) Expander() *strings.Replacer
- func (env Env) Int(key string) (int, bool)
- func (env Env) IntOrDefault(key string, def int) int
- func (env Env) String(key string) (string, bool)
- func (env Env) StringOrDefault(key string, def string) string
- func (env Env) StringWithTag(key string, tag string) (string, bool)
- func (env Env) StringWithTagOrDefault(key string, tag string, def string) string
- func (env Env) Var(key string) (any, bool)
- type Var
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoadDotenv ¶
LoadDotenv looks up .env and related files in the current directory and the in parent directories. Existing values are not overwritten by higher level files. Filenames considered are ".env" (usual .env files ), ".env.toml" (decoded as toml), where ".env" is evaluated before ".env.toml"
func ParseFlags ¶
ParseFlags parses (commandline) flags and returns them as key/value pairs. The following forms are permitted: -flag => just a boolean flag --flag => double dashes are also permitted -flag=x => single dash -flag x => single dash, no equal
Types ¶
type Env ¶
func Load ¶
Load loads environment variables from all available sources. It takes additional vars, which may be passed to the environment at runtime.
func (Env) Int ¶ added in v1.0.2
Int returns the int-value for the passed key if exists, otherwise, false
func (Env) IntOrDefault ¶ added in v1.0.2
IntOrDefault first tries to lookup the passed key, otherwise return def
func (Env) StringOrDefault ¶
StringOrDefault first tries to lookup the passed key, otherwise return def
func (Env) StringWithTag ¶
StringWithTag first to lookup "key.tag", otherwise return Env.String
func (Env) StringWithTagOrDefault ¶
StringWithTagOrDefault first tries to lookup "key.tag", otherwise return Env.StringOrDefault