env

package
v4.0.0-beta.4 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package env provides utilities for dealing with environment variables.

It is intended for internal use by buildkite-agent only.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsProtected

func IsProtected(name string) bool

IsProtected reports whether the environment variable is write-protected when the write is coming from job-level env or secrets.

func IsProtectedFromWithinJob

func IsProtectedFromWithinJob(name string) bool

IsProtectedFromWithinJob reports whether the environment variable is write- protected when the write is coming from within the job (including hooks and plugins).

func SeqSlice

func SeqSlice(s []string) iter.Seq2[string, string]

SeqSlice returns an iterator over all name/value pairs of env vars in a slice of strings.

func Split

func Split(l string) (name, value string, ok bool)

Split splits an environment variable (in the form "name=value") into the name and value substrings. If there is no '=', or the first '=' is at the start, it returns `"", "", false`.

Types

type Diff

type Diff struct {
	Added   map[string]string
	Changed map[string]DiffPair
	Removed map[string]struct{}
}

func (*Diff) Empty

func (diff *Diff) Empty() bool

func (*Diff) Keys

func (diff *Diff) Keys(yield func(string) bool)

Keys is an iterator over all env vars present in a diff.

func (*Diff) Remove

func (diff *Diff) Remove(key string)

type DiffPair

type DiffPair struct {
	Old string
	New string
}

type Environment

type Environment struct {
	// contains filtered or unexported fields
}

Environment is a map of environment variables, with the keys normalized for case-insensitive operating systems

func FromMap

func FromMap(m map[string]string) *Environment

func FromSlice

func FromSlice(s []string) *Environment

FromSlice creates a new environment from a string slice of KEY=VALUE

func New

func New() *Environment

func NewWithLength

func NewWithLength(length int) *Environment

func (*Environment) Apply

func (e *Environment) Apply(diff Diff)

func (*Environment) Copy

func (e *Environment) Copy() *Environment

Copy returns a copy of the env

func (*Environment) Diff

func (e *Environment) Diff(other *Environment) Diff

Diff returns a new environment with the keys and values from this environment which are different in the other one.

func (*Environment) Dump

func (e *Environment) Dump() map[string]string

Dump returns a copy of the environment with all keys normalized

func (*Environment) DumpPairs

func (e *Environment) DumpPairs() []Pair

DumpPairs returns a copy of the environment with all keys normalised.

func (*Environment) Exists

func (e *Environment) Exists(key string) bool

Exists returns true/false depending on whether or not the key exists in the env

func (*Environment) Get

func (e *Environment) Get(key string) (string, bool)

Get returns a key from the environment

func (*Environment) GetBool

func (e *Environment) GetBool(key string, defaultValue bool) bool

Get a boolean value from environment, with a default for empty. Supports true|false, on|off, 1|0

func (*Environment) GetInt

func (e *Environment) GetInt(key string, defaultValue int) int

GetInt gets an int value from environment, with a default for unset, empty, or invalid values.

func (*Environment) GetString

func (e *Environment) GetString(key, defaultValue string) string

GetString gets a string value from environment, with a default for unset or empty values.

func (*Environment) Length

func (e *Environment) Length() int

Length returns the length of the environment

func (*Environment) MarshalJSON

func (e *Environment) MarshalJSON() ([]byte, error)

func (*Environment) Merge

func (e *Environment) Merge(other *Environment)

Merge merges another env into this one and returns the result

func (*Environment) Remove

func (e *Environment) Remove(key string) string

Remove a key from the Environment and return its value

func (*Environment) Set

func (e *Environment) Set(key, value string)

Set sets a key in the environment

func (*Environment) ToSlice

func (e *Environment) ToSlice() []string

ToSlice returns a sorted slice representation of the environment

func (*Environment) UnmarshalJSON

func (e *Environment) UnmarshalJSON(data []byte) error

type Pair

type Pair struct{ Name, Value string }

Pair is an environment variable name/value pair.

Jump to

Keyboard shortcuts

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