fftoml

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2021 License: Apache-2.0 Imports: 5 Imported by: 2

Documentation

Overview

Package fftoml provides a TOML config file paser.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parser

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

Parser is a parser for TOML file format. Flags and their values are read from the key/value pairs defined in the config file.

Types

type ConfigFileParser

type ConfigFileParser struct {
	// contains filtered or unexported fields
}

ConfigFileParser is a parser for the TOML file format. Flags and their values are read from the key/value pairs defined in the config file. Nested tables and keys are concatenated with a delimiter to derive the relevant flag name.

func New

func New(opts ...Option) (c ConfigFileParser)

New constructs and configures a ConfigFileParser using the provided options.

func (ConfigFileParser) Parse

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

Parse parses the provided io.Reader as a TOML file and uses the provided set function to set flag names derived from the tables names and their key/value pairs.

type Option

type Option func(*ConfigFileParser)

Option is a function which changes the behavior of the TOML config file parser.

func WithTableDelimiter

func WithTableDelimiter(d string) Option

WithTableDelimiter is an option which configures a delimiter used to prefix table names onto keys when constructing their associated flag name. The default delimiter is "."

For example, given the following TOML

[section.subsection]
value = 10

Parse will match to a flag with the name `-section.subsection.value` by default. If the delimiter is "-", Parse will match to `-section-subsection-value` instead.

type ParseError

type ParseError struct {
	Inner error
}

ParseError wraps all errors originating from the TOML parser.

func (ParseError) Error

func (e ParseError) Error() string

Error implenents the error interface.

func (ParseError) Unwrap

func (e ParseError) Unwrap() error

Unwrap implements the xerrors.Wrapper interface, allowing xerrors.Is and xerrors.As to work with ParseErrors.

Jump to

Keyboard shortcuts

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