Documentation ¶
Overview ¶
Package exprs provides primitives for working with v1alpha1/expr values.
Index ¶
- type Matcher
- func MatchAny(e **expr.Expr) Matcher
- func MatchAnyFloat(value *float64) Matcher
- func MatchAnyFunction(name *string, args ...Matcher) Matcher
- func MatchAnyInt(value *int64) Matcher
- func MatchAnyMember(operand Matcher, field *string) Matcher
- func MatchAnyString(value *string) Matcher
- func MatchAnyText(text *string) Matcher
- func MatchFloat(value float64) Matcher
- func MatchFunction(name string, args ...Matcher) Matcher
- func MatchInt(value int64) Matcher
- func MatchMember(operand Matcher, field string) Matcher
- func MatchString(s string) Matcher
- func MatchText(text string) Matcher
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Matcher ¶
Matcher returns true if the expr matches the predicate.
func MatchAnyFloat ¶
MatchAnyFloat matches an expr.Constant_DoubleValue with any value. The value of the expr is populated in argument value.
func MatchAnyFunction ¶
MatchAnyFunction matches an expr.Expr_Call where the provided args matches the function arguments. The name of the function is populated in argument name.
func MatchAnyInt ¶
MatchAnyInt matches an expr.Constant_Int64Value with any value. The value of the expr is populated in argument value.
func MatchAnyMember ¶
MatchAnyMember matches an expr.Expr_Select where the operand matches the argument operand. The field of the expr is populated in argument field.
func MatchAnyString ¶
MatchAnyString matches an expr.Constant_StringValue with any value. The value of the expr is populated in argument value.
func MatchAnyText ¶
MatchAnyText matches an expr.Expr_Ident with any name. The name of the expr is populated in argument text.
func MatchFloat ¶
MatchFloat matches an expr.Constant_DoubleValue with an exact value.
func MatchFunction ¶
MatchFunction matches an expr.Expr_Call where the name of the expr matches argument name, and arguments of the function matches the provided args (length must match).
Example (ValidateResourceNames) ¶
const pattern = "books/{book}" var walkErr error walkFn := func(currExpr, _ *expr.Expr) bool { var name string // match any function expression with name '=' and LHS 'name' matcher := MatchFunction(filtering.FunctionEquals, MatchText("name"), MatchAnyString(&name)) if matcher(currExpr) && !resourcename.Match(pattern, name) { walkErr = fmt.Errorf("expected resource name matching '%s' but got '%s'", pattern, name) return false } return true } // name = "not a resource name" or name = "books/2" invalidExpr := filtering.Or( filtering.Equals(filtering.Text("name"), filtering.String("not a resource name")), filtering.Equals(filtering.Text("name"), filtering.String("books/2")), ) filtering.Walk(walkFn, invalidExpr) fmt.Println(walkErr) // reset walkErr = nil // name = "books/1" or name = "books/2" validExpr := filtering.Or( filtering.Equals(filtering.Text("name"), filtering.String("books/1")), filtering.Equals(filtering.Text("name"), filtering.String("books/2")), ) filtering.Walk(walkFn, validExpr) fmt.Println(walkErr)
Output: expected resource name matching 'books/{book}' but got 'not a resource name' <nil>
func MatchMember ¶
MatchMember matches an expr.Expr_Select where the operand matches the argument operand, and the field matches argument field.
func MatchString ¶
MatchString matches an expr.Constant_StringValue with an exact value.