env

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2026 License: MIT Imports: 2 Imported by: 0

README

Per-Request Settings

Lets the shared human daemon serve many requests at once while keeping each one's settings separate. Your environment values stay isolated and never leak between concurrent commands.

  • Keeps each request's settings separate
  • Prevents one command's values leaking into another
  • Forwards your environment to the daemon safely
  • Falls back to normal lookup outside the daemon
  • Works the same for direct CLI runs

Documentation

Overview

Package env provides per-request environment variable lookup that avoids mutating the process environment.

The daemon serves multiple concurrent client requests in the same process. Forwarding client env vars by mutating os.Environ would either require a process-wide mutex held across cmd.Execute() (which serialises all command execution) or risk cross-request contamination (one client's env value leaking into another client's command).

Instead, the daemon attaches a per-request env map to the cobra command's context and code that previously called os.Getenv now calls env.Lookup(ctx, key). The lookup falls back to os.Getenv when no per-request map is present so direct CLI invocations behave normally.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Lookup

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

Lookup returns the value for key, preferring the per-request env map stored on ctx and falling back to the process environment.

func WithEnv

func WithEnv(ctx context.Context, env map[string]string) context.Context

WithEnv returns ctx augmented with the given env map. The map is looked up first by Lookup before falling back to os.Getenv.

Types

This section is empty.

Jump to

Keyboard shortcuts

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