open-nomad/vendor/github.com/hashicorp/go-envparse
Seth Hoenig 435c0d9fc8 deps: Switch to Go modules for dependency management
This PR switches the Nomad repository from using govendor to Go modules
for managing dependencies. Aspects of the Nomad workflow remain pretty
much the same. The usual Makefile targets should continue to work as
they always did. The API submodule simply defers to the parent Nomad
version on the repository, keeping the semantics of API versioning that
currently exists.
2020-06-02 14:30:36 -05:00
..
.appveyor.yml deps: Switch to Go modules for dependency management 2020-06-02 14:30:36 -05:00
.gitignore deps: Switch to Go modules for dependency management 2020-06-02 14:30:36 -05:00
.travis.yml deps: Switch to Go modules for dependency management 2020-06-02 14:30:36 -05:00
envparse.go Update go-envparse to allow dots in env vars 2018-01-22 14:02:39 -08:00
LICENSE Switch to hashicorp/go-envparse 2017-06-02 15:58:52 -07:00
NOTICES.txt Switch to hashicorp/go-envparse 2017-06-02 15:58:52 -07:00
README.md Switch to hashicorp/go-envparse 2017-06-02 15:58:52 -07:00

GoDoc Build Status Coverage Status

go-envparse

A minimal Go environment variable parser. It's intended to be used to parse .env style files similar to godotenv or rubydotenv, but perform minimal allocations, handle more complex quoting, and be better tested.

Parsing a line does 2 allocations regardless of line length or complexity.

The parser supports JSON strings which allows for cross-language/platform encoding of arbitrarily complex data.

For example if you are parsing environment variables from a templated file, the template can JSON encode data that may contain newlines:

FOO={{ some_template_function | toJSON }}

...would be templated to:

FOO="The template value\nmay have included\nsome newlines!\n\ud83d\udd25"

...and envparse.Parse() would return:

map[string]string{
	"FOO": "The template value\nmay have included\nsome newlines!\n🔥",
}

Minimal

The following common features are intentionaly missing:

  • Full shell quoting semantics
  • Full shell escape sequence support
    • Only JSON escape sequences are supported (see below)
  • Variable interpolation
  • Anything YAML related
    • No

However, comments, unquoted, single quoted, and double quoted text may all be used within a single value:

SOME_KEY = normal unquoted \text 'plus single quoted\' "\"double quoted " # EOL

...parses to:

map[string]string{
	"SOME_KEY": `normal unquoted \text plus single quoted\ "double quoted `
}

(Note the trailing space inside the double quote is kept, but the space between the final " and # is trimmed.)

Format

  • Keys should be of the form: [A-Za-z_][A-Za-z0-9_]?
    • Keys may be prefixed with export which will be ignored
    • Whitespace around keys will be trimmed
  • Values should be valid ASCII or UTF-8 encoded.
  • Newlines are always treated as delimiters, so newlines within values must be escaped.
  • Values may use one of more quoting styles:
    • Unquoted - FOO=bar baz
      • No escape sequences
      • Ends at #, ", ', or newline
      • Preceeding and trailing whitespace will be trimmed
    • Double Quotes - FOO="bar baz"
      • Supports JSON escape sequences: \uXXXX, \r, \n, \t, \\, and \"
      • Ends at unescaped "
      • No whitespace trimming
    • Single Quotes - FOO='bar baz'
      • No escape sequences
      • Ends at '
      • No whitespace trimming

See envparse_test.go for examples of valid and invalid data.