env

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2023 License: MIT Imports: 8 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadDotenv

func LoadDotenv() map[string]any

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

func ParseFlags(args []string) map[string]any

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

type Env map[string]any

func Glob

func Glob() Env

func Load

func Load(vars ...Var) Env

Load loads environment variables from all available sources. It takes additional vars, which may be passed to the environment at runtime.

func (Env) Expander

func (env Env) Expander() *strings.Replacer

func (Env) Int added in v1.0.2

func (env Env) Int(key string) (int, bool)

Int returns the int-value for the passed key if exists, otherwise, false

func (Env) IntOrDefault added in v1.0.2

func (env Env) IntOrDefault(key string, def int) int

IntOrDefault first tries to lookup the passed key, otherwise return def

func (Env) String

func (env Env) String(key string) (string, bool)

String returns the string-value for the passed key if exists, otherwise, false

func (Env) StringOrDefault

func (env Env) StringOrDefault(key string, def string) string

StringOrDefault first tries to lookup the passed key, otherwise return def

func (Env) StringWithTag

func (env Env) StringWithTag(key string, tag string) (string, bool)

StringWithTag first to lookup "key.tag", otherwise return Env.String

func (Env) StringWithTagOrDefault

func (env Env) StringWithTagOrDefault(key string, tag string, def string) string

StringWithTagOrDefault first tries to lookup "key.tag", otherwise return Env.StringOrDefault

func (Env) Var

func (env Env) Var(key string) (any, bool)

Var returns the value for the passed key if exists, otherwise, false

type Var

type Var struct {
	Key   string
	Value any
}

func MkVar

func MkVar(k string, v any) Var

Jump to

Keyboard shortcuts

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