envfile

package
v1.26.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package envfile reads files of environment variables, one NAME=value a line, as the .env files many tools keep beside a project.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Var

type Var struct {
	Name  string
	Value string
}

Var is a variable a file sets.

func Parse

func Parse(r io.Reader) ([]Var, error)

Parse reads variables from r, in the order they are written:

# a comment
NAME=value
export NAME=value
NAME="a value with spaces, \n for a newline and \" for a quote"
NAME='a value taken as it is, $ and \ included'
NAME=value # a comment after a value that is not quoted

A value that is not quoted has the spaces around it removed. A value in double quotes may go on over several lines. Nothing is expanded: $OTHER in a value is those characters. A name written twice is returned twice, for the last to win.

An error starts with the line it is about, as "3: ...".

func Read

func Read(path string) ([]Var, error)

Read reads the variables of the file at path, in the order they are written. An error names the file and the line.

Jump to

Keyboard shortcuts

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