env

package
v1.28.0 Latest Latest
Warning

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

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

Documentation

Overview

Package env loads environment variables from env.yaml / env.local.yaml files into the real OS environment at package init time, following dotenv conventions. See CLAUDE.md for design rationale.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(key string) string

Get returns the value of the environment variable. It is a thin wrapper over os.Getenv. yaml-loaded values are visible because Load has populated the OS environment at package init. Environment variable keys are case-sensitive.

func Load added in v1.28.0

func Load()

Load walks ancestor directories from the current working directory up to the filesystem root, merges all env.yaml and env.local.yaml entries respecting precedence (subdirectory over ancestor; .local over non-local), and writes the merged result into the OS environment via os.Setenv.

Real OS environment variables set before the binary launches always win — this matches the dotenv convention used by godotenv, python-dotenv, Node dotenv, and others. Operators who set values via systemd/k8s/docker get those values; yaml is a fallback for keys that are otherwise unset.

Load is called automatically at package init. It can be called again to reload yaml changes, but in normal use the init-time invocation is sufficient.

func Lookup

func Lookup(key string) (string, bool)

Lookup returns the value of the environment variable. It is a thin wrapper over os.LookupEnv. yaml-loaded values are visible because Load has populated the OS environment at package init. Environment variable keys are case-sensitive.

func Pop

func Pop(key string)

Pop restores the environment variable to the value captured by the most recent Push. Calling Pop without a matching Push panics.

func Push

func Push(key string, value string)

Push sets an environment variable and remembers the prior OS env state so Pop can restore it. Push is goroutine-safe but the global env it mutates is not — tests using Push must not run with t.Parallel.

Pushed values are visible to any code reading os.Getenv, including third-party libraries that read env vars directly. This is what makes Push/Pop useful for controlling third-party SDK behavior in tests.

Types

This section is empty.

Jump to

Keyboard shortcuts

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