envparser

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeEnv

func EncodeEnv(w io.Writer, env map[string]string) error

func EnvMapFromReader

func EnvMapFromReader(r io.Reader) map[string]string

EnvMapFromReader reads a .env formatted file from the given path, and returns a map of key/value pairs

func LoadEnv

func LoadEnv(toLoad map[string]Variable, loaders ...EnvLoader) (map[string]string, error)

LoadEnv loads the environment variables from the given reader The loaders function is used to load the value of an environment variable

first-non-nil loader wins if no loader is non-nil, then the default is used, or an error is returned

func ParseKV

func ParseKV(kv string) (string, string, error)

func ParseTemplateVars

func ParseTemplateVars(r io.Reader) (map[string]Variable, error)

ParseTemplateVars returns a map of environment variables that are referenced in the given reader

The map key is the variable name, and the value is the right hand side of the expression

Types

type EnvLoader

type EnvLoader func(string) *string

func LoadEnvReader

func LoadEnvReader(r io.Reader) EnvLoader

LoadEnvReader reads a .env formatted file from the given path, and returns a loader function

func LoadKV

func LoadKV(kv map[string]string) EnvLoader

LoadKV returns a loader function that loads the given key/value pairs from the map

func LoadKVs

func LoadKVs(kvs []string) EnvLoader

type Variable

type Variable struct {
	// Name of the variable
	Name string

	// UnsetEmpty is true if the variable should be empty if it is not set,
	// rather than non-existent
	UnsetEmpty bool

	// Short form is the form without braces
	Short bool

	// If Default is empty, and the value is not set, then the value is defaulted
	Default string
	// If Error is not empty, and the value is not set, then the error is returned
	Error string
}

Variable is the right hand side of an environment variable expression

Jump to

Keyboard shortcuts

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