env

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package env implements helper functions for dealing with environment variables.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(env []string) (map[string]string, error)

Parse parses a list of environment variables of the form key=value into a map from keys to values. If a key appears multiple times, the last value of the key is returned.

Example
vars, err := Parse([]string{
	"name=alice",
	"pet=cat",
	"name=bob", // bob overwrites alice
})
if err != nil {
	panic(err)
}
fmt.Println(vars["name"])
fmt.Println(vars["pet"])
Output:

bob
cat

func Split

func Split(kv string) (string, string, error)

Split splits an environment variable of the form key=value into its constituent key and value parts.

Example
key, value, err := Split("name=ava")
if err != nil {
	panic(err)
}
fmt.Println(key)
fmt.Println(value)
Output:

name
ava

Types

This section is empty.

Jump to

Keyboard shortcuts

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