Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type NodeFilterFn ¶
type NodeFilterFn func(node interface{}) bool
NodeFilterFn represents a user-defined filter function, for use with Query.SetFilter().
The return value of the function must indicate if 'node' is to be included at this stage of the TOML path. Returning true will include the node, and returning false will exclude it.
NOTE: Care should be taken to write script callbacks such that they are safe to use from multiple goroutines.
Example (FilterExample) ¶
tree, _ := toml.Load(` [struct_one] foo = "foo" bar = "bar" [struct_two] baz = "baz" gorf = "gorf" `) // create a query that references a user-defined-filter query, _ := Compile("$[?(bazOnly)]") // define the filter, and assign it to the query query.SetFilter("bazOnly", func(node interface{}) bool { if tree, ok := node.(*toml.Tree); ok { return tree.Has("baz") } return false // reject all other node types }) // results contain only the 'struct_two' Tree query.Execute(tree)
Output:
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
A Query is the representation of a compiled TOML path. A Query is safe for concurrent use by multiple goroutines.
Example (QueryExample) ¶
config, _ := toml.Load(` [[book]] title = "The Stand" author = "Stephen King" [[book]] title = "For Whom the Bell Tolls" author = "Ernest Hemmingway" [[book]] title = "Neuromancer" author = "William Gibson" `) // find and print all the authors in the document query, _ := Compile("$.book.author") authors := query.Execute(config) for _, name := range authors.Values() { fmt.Println(name) }
Output:
func Compile ¶
Compile compiles a TOML path expression. The returned Query can be used to match elements within a Tree and its descendants. See Execute.
func (*Query) Execute ¶
Execute executes a query against a Tree, and returns the result of the query.
func (*Query) SetFilter ¶
func (q *Query) SetFilter(name string, fn NodeFilterFn)
SetFilter sets a user-defined filter function. These may be used inside "?(..)" query expressions to filter TOML document elements within a query.
type Result ¶
type Result struct {
// contains filtered or unexported fields
}
Result is the result of Executing a Query.
func CompileAndExecute ¶
CompileAndExecute is a shorthand for Compile(path) followed by Execute(tree).