Documentation
¶
Overview ¶
Package semantics implements TSL tree semantics.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Walk ¶
Walk traverses the TSL tree and implements search semantics.
Users can call the Walk method to check if a document compiles to `true` or `false` when applied to a tsl tree.
Example:
record := map[string]interface{} { "title": "A good book", "author": "Joe", "spec.pages": 14, "spec.rating": 5, "created_at": time.Now(), "is_active": true, } // evalFactory creates an evaluation function for a data record. func evalFactory(r map[string]interface{}) semantics.EvalFunc { // Returns: // A function (semantics.EvalFunc) that gets a `key` for a record and returns // the value of the document for that key. // If no value can be found for this `key` in our record, it will return // ok = false, if value is found it will return ok = true. return func(k string) (interface{}, bool) { if v, ok := book[k]; ok { return v, true } return nil, false } } // Check if our record complies with our tsl tree. // // For example: // if our tsl tree represents the phrase "author = 'Joe' and created_at > '2023-01-01'" // we will get the boolean value `true` for our record. // // if our tsl tree represents the phrase "spec.pages > 50" // we will get the boolean value `false` for our record. eval := evalFactory(record) compliance, err = semantics.Walk(tree, eval)
Types ¶
Click to show internal directories.
Click to hide internal directories.