ffenv

package
v4.0.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package ffenv provides an .env config file parser.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidLine = errors.New("invalid line")

ErrInvalidLine is returned when the parser encounters an invalid line.

Functions

func Parse

func Parse(r io.Reader, set func(name, value string) error) error

Parse is a parser for .env files.

Each line in the .env file is tokenized on the first `=` character. The first token is interpreted as the env var representation of the flag name, and the second token is interpreted as the value. Both tokens are trimmed of leading and trailing whitespace. If the value is "double quoted", control characters like `\n` are expanded. Lines beginning with `#` are interpreted as comments. End-of-line comments are not supported.

Parse options related to environment variables, like [ff.WithEnvVarPrefix], [ff.WithEnvVarShortNames], and [ff.WithEnvVarCaseSensitive], also apply to .env files. For example, WithEnvVarPrefix("MYPROG") means that the keys in an .env file must begin with MYPROG_.

If for any reason any key in an .env file matches multiple flags, parse will return [ff.ErrDuplicateFlag]. This can happen if you have flags with names that differ only in capitalization, e.g. `-v` and `-V`. If you want to support setting these flags from an .env file, either use discrete long names, or [ff.WithEnvVarCaseSensitive].

Using the .env config file parser doesn't automatically enable parsing of actual environment variables. To do so, callers must still explicitly provide e.g. [ff.WithEnvVars] or [ff.WithEnvVarPrefix].

Types

This section is empty.

Jump to

Keyboard shortcuts

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