env

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package env is a context-driven wrapper for access to environment variable. It allows substitution of mock environments via context.Context for testing and other purposes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clearenv

func Clearenv(ctx context.Context)

func Environ

func Environ(ctx context.Context) []string

func ExpandEnv

func ExpandEnv(ctx context.Context, s string) string

func Getenv

func Getenv(ctx context.Context, key string) string

func LookupEnv

func LookupEnv(ctx context.Context, key string) (string, bool)

func Onto

func Onto(ctx context.Context, env Env) context.Context

Onto sets the context Env. Pass nil to revert to the default system env.

func Setenv

func Setenv(ctx context.Context, key, value string) error

func Unsetenv

func Unsetenv(ctx context.Context, key string) error

Types

type Env

type Env interface {
	Clearenv()
	Environ() []string
	LookupEnv(key string) (string, bool)
	Setenv(key, value string) error
	Unsetenv(key string) error
}

Env models the envvar functions of the os package.

func From

func From(ctx context.Context) Env

From gets the Env from the Context.

type Map

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

Map implements an Env backed on a map[string]string.

func NewMap

func NewMap(initialEnv map[string]string) *Map

func (*Map) Clearenv

func (m *Map) Clearenv()

func (*Map) Environ

func (m *Map) Environ() []string

func (*Map) LookupEnv

func (m *Map) LookupEnv(key string) (string, bool)

func (*Map) Setenv

func (m *Map) Setenv(key, value string) error

func (*Map) Unsetenv

func (m *Map) Unsetenv(key string) error

Jump to

Keyboard shortcuts

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