Documentation
¶
Overview ¶
Package envfile reads and writes the .env format.
There is no specification for it. Every tool that reads one agrees on `KEY=value` and disagrees about the rest, so the subset implemented here is the intersection of what the common readers accept, and each departure from the loosest possible reading is a deliberate choice to fail rather than to guess:
- Blank lines and lines whose first non-space character is # are skipped.
- A leading `export ` is allowed and ignored, so a file written to be sourced by a shell can be read here unchanged.
- A bare value ends at the end of the line. An unquoted # does NOT begin a comment, because a password of pa55word#1 is far more common than an inline comment, and dropping half a credential is a failure nobody sees until something cannot authenticate.
- A single-quoted value is literal. A double-quoted value understands \n, \r, \t, \\ and \", which is what makes a certificate fit on one line. Either kind may span several lines, because a certificate that does not fit on one is the other way people write it.
- A key that appears twice is an error rather than a last-one-wins, since the two lines disagree and only the author knows which was meant.
- Text after a closing quote is an error, except a comment. The value has already ended, so keeping the part before the quote would be a guess about which half of the line was meant.
- A byte order mark on the first line is dropped. Several editors write one and none of them mention it, and a key that begins with an invisible character matches nothing anywhere.
- Carriage returns are dropped with the line ending, so a file written on Windows reads the same as one written anywhere else.
Nothing here talks to the network or the filesystem. It turns text into variables and variables into text, which is what makes both directions testable and what keeps the format in one place instead of in two commands.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ParseError ¶
ParseError is a line that could not be read, named by line number.
func (*ParseError) Error ¶
func (e *ParseError) Error() string
type Var ¶
type Var struct {
Key string
Value string
// Line is where it was found, for an error that can be acted on.
Line int
}
Var is one variable in a file.