Documentation
¶
Overview ¶
Package dotenv provides a line-preserving scanner and emitter for dotenv files. Unlike map-based parsers, it retains original bytes, ordering, comments, blank lines, and line terminators so that unmodified lines pass through byte-for-byte and only resolved values are rewritten.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Emit ¶
func Emit(w io.Writer, lines []Line, style QuoteStyle) error
Emit writes lines to w. Non-KeyVal lines and unresolved KeyVal lines are written verbatim (Raw+Ending). Resolved KeyVal lines are rewritten as Key=quote(Value, style)+Ending. A resolved value containing a raw newline is rejected regardless of style.
Types ¶
type Line ¶
type Line struct {
Raw string // exact original bytes of the line, WITHOUT the line terminator
Ending string // the terminator that followed Raw: "\n", "\r\n", or "" (last line without a trailing newline)
Kind LineKind
Key string // set only for KindKeyVal
Value string // raw value substring for KindKeyVal (may contain '='), as it appeared in the source
Resolved bool // false from Scan; the render pipeline sets true after replacing Value with a resolved secret
}
Line is one physical line of a dotenv file.
type LineKind ¶
type LineKind int
LineKind classifies a physical line of a dotenv file.
const ( // KindBlank is an empty line or one containing only whitespace. KindBlank LineKind = iota // KindComment is a line whose first non-whitespace byte is '#'. KindComment // KindKeyVal is a well-formed KEY=VALUE line. KindKeyVal // KindOther is any non-blank, non-comment line without an '='. KindOther )
type QuoteStyle ¶ added in v0.2.0
type QuoteStyle int
QuoteStyle selects how resolved values are quoted on emit.
const ( // QuoteMinimal is the default, byte-faithful quoting: values are emitted // bare unless they contain a shell-significant byte, in which case they are // double-quoted with '\' and '"' escaped. QuoteMinimal QuoteStyle = iota // QuoteShell produces output safe for a POSIX shell that consumes the file // via `source`/`.`: values are single-quoted (everything inside single // quotes is literal) unless they are a "boring" token. QuoteShell )