Documentation
¶
Overview ¶
Package tq encapsulates the logic of the Tq program behind a public interface. It reads input data from the input reader, processes it with the interpreted query string, and writes output data to the output writer.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Tq ¶
type Tq struct {
// contains filtered or unexported fields
}
Tq accepts TOML data from input and produces the result TOML data to output. The process of data decoding and encoding is handled by the adapter. The query passed to the Run method string is interpreted and executed against the input data to produce the output data.
func (*Tq) Run ¶
Run executes the query string against the input data and writes the output data to the output writer.
Example ¶
ExampleTq_Run demonstrates how to use the Tq struct to run a query against TOML data. The example uses a TOML configuration file with two servers and queries for IP addresses on the first server. The output is written to the standard output.
input := strings.NewReader(` [servers] [servers.alpha] ip = "10.0.0.1" role = "frontend" [servers.beta] ip = "10.0.0.2" role = "backend" `) var output bytes.Buffer query := ` .servers .alpha .ip ` config := toml.GoTOMLConf{} goToml := toml.NewGoTOML(config) adapter := toml.NewAdapter(goToml) tq := tq.New(adapter) _ = tq.Run(input, &output, query) fmt.Println(output.String())
Output: '10.0.0.1'
func (*Tq) Validate ¶
Validate checks if the query string is syntactically correct.
Example ¶
ExampleTq_Validate shows how to use the Tq struct to validate whether a given query is syntactically correct. The example shows how the error is reported and represented as a string.
query := "['servers'][['ip']" config := toml.GoTOMLConf{} goToml := toml.NewGoTOML(config) adapter := toml.NewAdapter(goToml) tq := tq.New(adapter) err := tq.Validate(query) fmt.Println(err)
Output: ['servers'][['ip'] ^ Parser error: expected ']' to terminate selector; got '['
Directories
¶
Path | Synopsis |
---|---|
cmd
|
|
tq
tq - query TOML configuration files
|
tq - query TOML configuration files |
internal
|
|
ast
Package ast contains the implementation of the tq expression nodes that serve as building blocks of the query language abstract syntax tree.
|
Package ast contains the implementation of the tq expression nodes that serve as building blocks of the query language abstract syntax tree. |
interpreter
Package interpreter provides the Interpreter struct that implements the ast.Visitor interface allowing it to walk and interpret the tq AST into sequence of filtering functions processing TOML input data as specified in the query.
|
Package interpreter provides the Interpreter struct that implements the ast.Visitor interface allowing it to walk and interpret the tq AST into sequence of filtering functions processing TOML input data as specified in the query. |
lexer
Package lexer provides a Lexer struct that converts a string of scanned characters into allowed tq lexemes.
|
Package lexer provides a Lexer struct that converts a string of scanned characters into allowed tq lexemes. |
parser
Package parser provides a Parser struct that parses lexer tokens from the tq query into an AST.
|
Package parser provides a Parser struct that parses lexer tokens from the tq query into an AST. |
Package toml declares an adapter for external TOML packages to accommodate for different implementations of data encoders and decoders.
|
Package toml declares an adapter for external TOML packages to accommodate for different implementations of data encoders and decoders. |