env

package
v0.19.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: BSD-3-Clause, MIT Imports: 12 Imported by: 0

Documentation

Overview

Package env provides functionality to dynamically load the environment variables

Note: This is just a modified copy and wrapper around the gotenv package by suboisto

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownVariable = fmt.Errorf("unknown variable")
	ErrCyclicVariable  = fmt.Errorf("cyclic variable")
)
View Source
var Files = []string{"ntt.env", "k3.env"}

Functions

func Apply added in v0.16.2

func Apply(r io.Reader) error

Apply is a function to load an io Reader then export the valid variables into environment variables if they do not exist.

func Environ added in v0.16.2

func Environ() []string

Environ returns the current process's environment as a string-slice of the form key=value. It also replaces K3-prefixes with NTT-prefixes.

func Expand added in v0.16.2

func Expand(v string, env Env) (string, error)

Expand expands variable references recursively.

func ExpandAll added in v0.16.2

func ExpandAll(v interface{}, env Env) error

func Getenv

func Getenv(key string) string

Lookup key in process environment. Is key begins with "NTT_" also lookup key with "K3_" prefix.

func Load

func Load(filenames ...string) error

Load is a function to load a file or multiple files and then export the valid variables into environment variables if they do not exist. When it's called with no argument, it will load `.env` file on the current path and set the environment variables. Otherwise, it will loop over the filenames parameter and set the proper environment variables.

func LoadFiles added in v0.16.2

func LoadFiles(files ...string)

LoadFiles environment files ntt.env and k3.env

func LookupEnv

func LookupEnv(key string) (string, bool)

LookupEnv is like Getenv, but returns a true boolean when key exists

func Must added in v0.16.2

func Must(fn func(filenames ...string) error, filenames ...string)

Must is wrapper function that will panic when supplied function returns an error.

func OverApply added in v0.16.2

func OverApply(r io.Reader) error

OverApply is a function to load an io Reader then export and override the valid variables into environment variables.

func OverLoad added in v0.16.2

func OverLoad(filenames ...string) error

OverLoad is a function to load a file or multiple files and then export and override the valid variables into environment variables.

Types

type Env

type Env map[string]string

Env holds key/value pair of valid environment variable

func EnvironMap added in v0.16.2

func EnvironMap() Env

EnvironMap returns the current process's environment as a string-map. It also replaces K3-prefixes with NTT-prefixes.

func Parse

func Parse(r io.Reader) Env

Parse is a function to parse line by line any io.Reader supplied and returns the valid Env key/value pair of valid variables. It expands the value of a variable from the environment variable but does not set the value to the environment itself. This function is skipping any invalid lines and only processing the valid one.

func ParseFiles added in v0.16.2

func ParseFiles(files ...string) Env

ParseFiles environment files ntt.env and k3.env

func StrictParse added in v0.16.2

func StrictParse(r io.Reader) (Env, error)

StrictParse is a function to parse line by line any io.Reader supplied and returns the valid Env key/value pair of valid variables. It expands the value of a variable from the environment variable but does not set the value to the environment itself. This function is returning an error if there are any invalid lines.

func (Env) Expand added in v0.16.2

func (env Env) Expand() error

Expand variable references recursively. Environment variables overwrite variables defined in environment files. Undefined variables won't be expanded and will return an error.

func (Env) Slice added in v0.16.2

func (env Env) Slice() []string

Slice returns a sorted string slice of the variables.

Jump to

Keyboard shortcuts

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