envfile

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package envfile loads simple dotenv-style files without overriding process environment values.

Index

Constants

View Source
const (
	// MaxLineBytes is the maximum logical line size accepted in an env file.
	MaxLineBytes = 1 << 20

	DiagnosticLineTooLong = "env_file_line_too_long"
)

Variables

This section is empty.

Functions

func Load added in v0.13.0

func Load(path string, explicit bool, process []string) (Environment, LoadResult, error)

Load parses path into an explicit environment overlay without mutating the process environment.

func LookupPath

func LookupPath(projectRoot string, explicit string) (string, bool, error)

LookupPath resolves the env file for a project root. explicit wins. Without an explicit path, .env.<GOWDK_ENV> wins over .env when it exists.

Types

type DiagnosticError added in v0.13.0

type DiagnosticError struct {
	Code  string
	Path  string
	Line  int
	Limit int
}

DiagnosticError describes an env-file parse diagnostic without exposing the input value.

func (*DiagnosticError) Error added in v0.13.0

func (err *DiagnosticError) Error() string

type Entry

type Entry struct {
	Name  string
	Value string
}

Entry is one parsed env-file assignment.

func ParseFile

func ParseFile(path string) ([]Entry, error)

ParseFile parses KEY=value and export KEY=value lines. Values may be quoted with single or double quotes. Blank lines and # comments are ignored.

type Environment added in v0.13.0

type Environment struct {
	Process map[string]string
	File    map[string]string
}

Environment is an explicit environment overlay. Process values win over file values. Constructors and accessors make defensive copies so project loading can pass environments between concurrent workspaces without global mutable state.

func NewEnvironment added in v0.13.0

func NewEnvironment(process []string, entries []Entry) Environment

NewEnvironment constructs an overlay from a process-style NAME=value slice and parsed file entries.

func (Environment) ForSubprocess added in v0.13.0

func (env Environment) ForSubprocess(base []string) []string

ForSubprocess applies the file overlay to base without replacing explicitly supplied base values. Overlay-only names are appended in sorted order for deterministic tests and command construction.

func (Environment) Lookup added in v0.13.0

func (env Environment) Lookup(name string) (string, bool)

Lookup returns a process value first, then a file overlay value.

type LoadResult

type LoadResult struct {
	Path     string
	Loaded   bool
	Applied  []string
	Skipped  []string
	Explicit bool
}

LoadResult describes one env-file load without exposing values.

func LoadIntoEnv

func LoadIntoEnv(path string, explicit bool) (LoadResult, error)

LoadIntoEnv is retained for generated application startup compatibility. Compiler/project loading must use Load and pass the returned overlay explicitly. Existing process values always win.

Jump to

Keyboard shortcuts

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