Help us shape the future of Go! Take the 2026 Go Developer Survey

envfile

package
v0.48.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package envfile parses .env files into key/value pairs.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("no volcano.env file found.\ncreate volcano/volcano.env or use --file to specify a path")

ErrNotFound is returned when no path is given and neither default location holds an env file.

Functions

func HasKey added in v0.48.0

func HasKey(path string, keys ...string) (bool, error)

HasKey reports whether the env file at path sets any of keys. A missing file sets none.

func Key added in v0.48.0

func Key(line string) string

Key returns the key a KEY=value line sets, or "" for anything else.

func LoadFirstEnvVars

func LoadFirstEnvVars(candidates ...string) ([]string, error)

LoadFirstEnvVars reads the first existing env file from candidates and returns its variables as sorted KEY=value entries. If no candidate exists, it returns nil and no error.

func ResolvePath added in v0.45.0

func ResolvePath(fileArg string) (string, error)

ResolvePath returns the env file Load would read. An explicit path must exist; otherwise it looks for volcano/volcano.env and ./volcano.env, returns ErrNotFound when neither exists, and an error when both do.

func Upsert added in v0.48.0

func Upsert(path string, vars []Var, header ...string) error

Upsert sets vars in the env file at path, keeping every other line and comment as it is. A key already in the file is updated in place, so a rerun never adds a second copy. Later copies of a key are dropped: the last one would win when the file is read. A new file starts with header.

Types

type File

type File struct {
	Path      string
	Variables map[string]string
}

File is a loaded Volcano env file.

func Load

func Load(fileArg string) (*File, error)

Load resolves and reads the selected Volcano env file.

type Var added in v0.48.0

type Var struct {
	Key, Value string
}

Var is one KEY=value line Upsert writes.

Jump to

Keyboard shortcuts

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