envfile

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package envfile parses .env files and manipulates their contents. It supports shell-style variable substitution, quoted values, comments, environment merging, and conversion between string slices and its own environment map type.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Env

type Env map[string]string

Env represents a mapping of environment variable names to their values.

func EnvFromStrings

func EnvFromStrings(strs []string) Env

EnvFromStrings creates an Env from a slice of "KEY=VALUE" strings.

func Load

func Load(filePath string, subst bool, substEnv Env) (Env, error)

Load reads and parses an environment file at the given path. If subst is true, it performs variable substitution using values from the same file and substEnv.

func Merge

func Merge(envs ...Env) Env

Merge combines multiple environments into a single Env. Later environments override values from earlier ones.

func OS

func OS() Env

OS returns the current process environment as an Env.

func Parse

func Parse(r io.Reader, subst bool, substEnv Env) (Env, error)

Parse reads environment variables from an io.Reader and returns them as a map. If subst is true, it substitutes variables from the same env file and substEnv.

func (Env) Keys

func (e Env) Keys() []string

Keys returns a sorted slice of environment variable names.

func (Env) Strings

func (e Env) Strings() []string

Strings converts the environment map to a slice of "KEY=VALUE" strings.

Jump to

Keyboard shortcuts

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