dotenv

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package dotenv loads environment variables from .env files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(paths ...string) error

Load loads environment variables from .env files into the current process environment.

12-Factor Preservation: Existing OS environment variables are never overwritten.

Hierarchy: When paths is empty, Load automatically loads ".env" followed by ".env.local" from the current working directory if they exist (silently ignoring missing files). When explicit paths are provided, each file must exist or a DotenvError is returned.

Precedence: Files are applied in order: a key defined in more than one file takes the value from the last file that defines it, while keys already present in the process environment outrank every file.

Variable references resolve from the process environment first, then from keys defined earlier in the same file; a file that overrides a key already supplied by an earlier file in the same call expands to its own value.

func Parse

func Parse(data []byte) (map[string]string, error)

Parse parses raw .env file contents into a key-value map. Supports comments, export prefixes, unquoted, single-quoted, and double-quoted values with escape sequences. Variable references resolve from the process environment first, then from keys defined earlier in the file.

Types

type DotenvError

type DotenvError struct {
	Path  string
	Msg   string
	Cause error
}

DotenvError represents an error reading or parsing a .env file.

func (*DotenvError) Error

func (e *DotenvError) Error() string

func (*DotenvError) Is

func (e *DotenvError) Is(target error) bool

func (*DotenvError) Unwrap

func (e *DotenvError) Unwrap() error

Jump to

Keyboard shortcuts

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