envutil

package
v0.0.3 Latest Latest
Warning

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

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

Documentation

Overview

Package envutil holds the small, shared environment-handling helpers the build, deploy, and host-launch paths all need: a minimal .env parser and two env-overlay merges whose precedence is encoded in the name. Factoring them here ends a duplication where the same operation name (mergeEnv) meant opposite precedence in different packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MergeBaseWins

func MergeBaseWins(base []string, extra map[string]string) []string

MergeBaseWins layers extra KEY=VALUE pairs onto a base os.Environ() slice with base winning on key conflict (so a developer's shell override always wins). Non-conflicting extras are appended. Returns a fresh slice safe to assign to cmd.Env.

func MergeExtraWins

func MergeExtraWins(base []string, extra map[string]string) []string

MergeExtraWins layers extra KEY=VALUE pairs onto a base os.Environ() slice with extra winning on key conflict. Used where the overlay (env_file / BuildEnv) is meant to be authoritative for the variables it declares and the parent process's env is background context. Returns a fresh slice safe to assign to cmd.Env.

func ParseDotEnv

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

ParseDotEnv parses a .env file (KEY=VALUE per line, # comments, trailing whitespace trimmed) into a map. Quoted values ("VALUE", 'VALUE') have their outer quotes stripped. An optional leading "export " is stripped. Missing file returns os.ErrNotExist (wrapped) so callers can treat absence as non-fatal.

Intentionally minimal — we don't expand $VARS or `${VAR:-default}` shell features. Projects needing those should use direnv or a wrapper script; this helper is just enough for the common "DATABASE_URL=postgres://..." case the host-mode loop and the External deploy env_file overlay need.

Types

This section is empty.

Jump to

Keyboard shortcuts

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