env

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package env contains data structures and methods to assist with managing environment variables.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Env

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

Env represents a map of environment variables. By default, the keys are case-insensitive on Windows and case-sensitive on other platforms. If they are case-insensitive, the original casing is lost.

func New

func New(opts ...Options) *Env

New return a new `Env`. By default, it is case-insensitive on Windows and case-sensitive on other platforms. See `Options` for available options.

func (*Env) Get

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

Get returns the value of an environment variable and whether it was found. If the Env was created as case-insensitive, the key's case is normalised.

func (*Env) Set

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

Set adds an environment variable to the Env or updates an existing one by overwriting its value. If the Env was created as case-insensitive, the keys are case normalised.

type Options

type Options func(*Env)

Options are functional options for creating a new Env.

func CaseSensitive

func CaseSensitive(actuallyCaseSensitive bool) Options

CaseSensitive is an option that overrides previous case-sensitivity whether set by default or as an `Option`.

func FromMap

func FromMap(source map[string]string) Options

FromMap is an option that sets the Env to have the key-values pairs from the `source` map. The key-value pair will be inserted with the case sensitivity of the Env, which by default is case-insensitive on Windows and case-sensitive on other platforms. Note that random map iteration will cause the result to be non-deterministic if there are multiple keys in `source`, which are equivalent under case insensitivity, that have different corresponding values.

Jump to

Keyboard shortcuts

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