env

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package env provides pure, daemon-safe .env file parsing, merging, and atomic file updating into isolated in-memory maps.

Daemon-Safe Isolation

Unlike traditional dotenv libraries that mutate process-global state via os.Setenv or read ambient variables via os.Getenv, this package operates exclusively on isolated map[string]string values. In the TaskSmith Brain daemon, multiple workspaces, worktrees, and subagents execute concurrently within a single OS process. By forbidding global environment reads and mutations, credentials and configuration variables loaded for one workspace can never leak into or overwrite another workspace's environment.

Precedence and Merging

Environment maps can be layered deterministically using Merge, where later maps take precedence over earlier ones (for example, overlaying a workspace's local .tasksmith/.env on top of the global ~/.tasksmith/.env).

In-Place File Updates

SetInFile updates or appends individual environment variables in a .env file while preserving existing comments, blank lines, key ordering, and file permissions, creating new files with restrictive 0600 permissions by default.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadFile

func LoadFile(path string) (map[string]string, error)

LoadFile reads and parses a .env file at path. If the file does not exist, LoadFile returns an empty non-nil map and a nil error.

func Merge

func Merge(envs ...map[string]string) map[string]string

Merge combines the provided environment maps in order and returns a new isolated map. Keys in later maps override keys in earlier maps.

func Parse

func Parse(r io.Reader) (map[string]string, error)

Parse reads .env formatted content from r and returns an isolated map of key-value pairs. It never reads or mutates the process environment.

func SetInFile

func SetInFile(path, key, value string) error

SetInFile sets key=value in the .env file at path. If key already exists in the file, its line is updated in-place while preserving all comments, blank lines, and key ordering. Otherwise, key=value is appended at the end.

Parent directories are created as needed. Newly created files are written with 0600 permissions; existing files preserve their current permissions.

Types

This section is empty.

Jump to

Keyboard shortcuts

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