Documentation ¶
Index ¶
- type Dispenser
- func (d *Dispenser) ArgErr() error
- func (d *Dispenser) File() string
- func (d *Dispenser) Line() int
- func (d *Dispenser) Next() bool
- func (d *Dispenser) NextArg() bool
- func (d *Dispenser) NextBlock() bool
- func (d *Dispenser) NextLine() bool
- func (d *Dispenser) RemainingArgs() []string
- func (d *Dispenser) SetTokenSubstitutionFunc(fn TokenSubstitutionFunc)
- func (d *Dispenser) SyntaxErr(f string, args ...interface{}) error
- func (d *Dispenser) Unread() bool
- func (d *Dispenser) Val() string
- type Input
- type LoadFunc
- type Loader
- type Parser
- type SyntaxErr
- type Token
- type TokenSubstitutionFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dispenser ¶
type Dispenser struct {
// contains filtered or unexported fields
}
Dispenser operates on a stream of tokens and provides some handy methods for structure based decisions and token loading
func NewDispenser ¶
NewDispenser returns a new dispenser for the input reader. It panics if an error is encountered
func NewDispenserFromInput ¶
NewDispenserFromInput creates a new token dispenser from input. It panics if an error is encountered
func NewDispenserFromTokens ¶
NewDispenserFromTokens returns a new dispenser with the given tokens
func (*Dispenser) Next ¶
Next loads the next token in the stream. It returns true as long as a next token is available
func (*Dispenser) NextArg ¶
NextArg loads the next token as long as it's on the same line as the current token. It handles newlines in the current token correctly
func (*Dispenser) NextBlock ¶
NextBlock returns true as long as the next token either opens a new block or is already in a block. It does not support nested blocks
func (*Dispenser) NextLine ¶
NextLine loads the next token as long as it's on the next line or in a different file. Newlines in the current token are handled correctly
func (*Dispenser) RemainingArgs ¶
RemainingArgs returns all remaining arguments form the current line
func (*Dispenser) SetTokenSubstitutionFunc ¶
func (d *Dispenser) SetTokenSubstitutionFunc(fn TokenSubstitutionFunc)
SetTokenSubstitutionFunc sets a function to be called before returning the value of a token. It can be used to apply environment variable substitution or similar
type Input ¶
type Input interface { // Name returns the name of the input. // It's mostly used for error reporing Name() string // Content returns the complete content of the interface Content() (string, error) }
Input represents somekind of configuration input source
type LoadFunc ¶
type LoadFunc func() Input
LoadFunc loads the input and returns it. If the loader cannot provide a configuration input it should return nil
func ChainLoader ¶
ChainLoader chains configuration loaders and returns the input from the first loader to find one
func FileLoader ¶
FileLoader is a config.Loader that returns a file based config input
type Loader ¶
type Loader interface { // Load loads the input and returns it. If the loader cannot // provide a configuration input it should return nil Load() Input }
Loader is capabole of opeing a configuration input
type Parser ¶
type Parser struct { Dispenser // contains filtered or unexported fields }
Parser parses data from a dispenser
func NewParser ¶
NewParser creates a new parser for the given reader. It panics if something goes wrong
func NewParserFromDispenser ¶
NewParserFromDispenser returns a new parser using d
func NewParserFromInput ¶
NewParserFromInput returns a new parser from the given input. It panics if something goes wrong
func (*Parser) ForEachInOrder ¶
func (p *Parser) ForEachInOrder(directiveOrder []string, fn func(n string, d Dispenser) error) ([]string, error)
ForEachInOrder calls fn for each directive in the order they are listed in directiveOrder. fn is called with a new dispenser that has the whole set of tokens (prefixed and separated with the directive name itself). If fn returns an error the whole iteration is stopped and that error is returned from ForEachInOrder. The returned string slice includes all directive names that have not been handled because they were missing in directiveOrder. Use that slice to detect unknown directives in the config file
func (*Parser) Parse ¶
Parse parses the complete input file and returns the tokens grouped by directive usage
func (*Parser) UnknownDirectives ¶
UnknownDirectives returns a list of directive names that did not appear in knownDirectives. It is mainly meant for error reporting
type SyntaxErr ¶
type SyntaxErr struct { // File is the name of the file or input File string // Line is the line the error occured Line int // Text is the current token text Text string // Message is the error message Message string }
SyntaxErr is a syntax error found in a config input
type TokenSubstitutionFunc ¶
TokenSubstitutionFunc is called for each token value and can substitude or change the value of the token