envfile

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package envfile loads a dotenv file into a map.

Load reads a file at path and returns its KEY=VALUE pairs as a map. Each error names a line number and a key; no parsed value appears.

A blank line and a line starting with '#' (after leading whitespace) skip. The first '=' on a line splits the key from the value. Keys match the pattern [A-Za-z_][A-Za-z0-9_]*.

A line may start with the lowercase keyword 'export' followed by whitespace; the keyword is stripped before key validation. A value may be unquoted, single-quoted, or double-quoted; a double-quoted value decodes '\n', '\t', '\\', and '\"'. A trailing '#' comment outside quotes is stripped.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

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

Load reads the dotenv file at path and returns its KEY=VALUE pairs as a map. Load reads the file and delegates the parse to LoadBytes, so the two share one parser and one error set. Load returns a wrapped os.ErrNotExist when path does not exist. No returned error ever contains a parsed value.

func LoadBytes

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

LoadBytes parses an already-read dotenv body and returns its KEY=VALUE pairs as a map. A blank line and a line starting with '#' (after leading whitespace) skip. A value may be unquoted, single-quoted, or double-quoted; a double-quoted value decodes \n, \t, \\, and \". Only the first '=' on a line splits key from value, so a literal '=' in an unquoted or quoted value passes through. A duplicate key keeps its last value. A line may also start with the lowercase keyword 'export' followed by whitespace; the keyword is stripped before key validation. LoadBytes(nil) returns an empty map and a nil error. No returned error ever contains a parsed value.

Types

This section is empty.

Jump to

Keyboard shortcuts

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