dotenv

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 4 Imported by: 0

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) 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)+Ending. A resolved value containing a raw newline is rejected.

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.

func Scan

func Scan(r io.Reader) ([]Line, error)

Scan reads r fully and splits it into ordered, byte-faithful Lines. Each line's terminator is preserved in Ending ("\n", "\r\n", or "" for a final line lacking a newline). No trimming, quote-stripping, or resolution occurs.

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
)

Jump to

Keyboard shortcuts

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