kvfile

package
v27.4.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package kvfile provides utilities to parse line-delimited key/value files such as used for label-files and env-files.

File format

key/value files use the following syntax:

  • File must be valid UTF-8.
  • BOM headers are removed.
  • Leading whitespace is removed for each line.
  • Lines starting with "#" are ignored.
  • Empty lines are ignored.
  • Key/Value pairs are provided as "KEY[=<VALUE>]".
  • Maximum line-length is limited to bufio.MaxScanTokenSize.

Interpolation, substitution, and escaping

Both keys and values are used as-is; no interpolation, substitution or escaping is supported, and quotes are considered part of the key or value. Whitespace in values (including leading and trailing) is preserved. Given that the file format is line-delimited, neither key, nor value, can contain newlines.

Key/Value pairs

Key/Value pairs take the following format:

KEY[=<VALUE>]

KEY is required and may not contain whitespaces or NUL characters. Any other character (except for the "=" delimiter) are accepted, but it is recommended to use a subset of the POSIX portable character set, as outlined in Environment Variables.

VALUE is optional, but may be empty. If no value is provided (i.e., no equal sign ("=") is present), the KEY is omitted in the result, but some functions accept a lookup-function to provide a default value for the given key.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(filename string, lookupFn func(key string) (value string, found bool)) ([]string, error)

Parse parses a line-delimited key/value pairs separated by equal sign. It accepts a lookupFn to lookup default values for keys that do not define a value. An error is produced if parsing failed, the content contains invalid UTF-8 characters, or a key contains whitespaces.

func ParseFromReader

func ParseFromReader(r io.Reader, lookupFn func(key string) (value string, found bool)) ([]string, error)

ParseFromReader parses a line-delimited key/value pairs separated by equal sign. It accepts a lookupFn to lookup default values for keys that do not define a value. An error is produced if parsing failed, the content contains invalid UTF-8 characters, or a key contains whitespaces.

Types

This section is empty.

Jump to

Keyboard shortcuts

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