ExecuteSelector parses the selector and executes the resulting AST with the given input.
(ctx context.Context, selectorStr string, value *model.Value, opts *Options)
| 14 | |
| 15 | // ExecuteSelector parses the selector and executes the resulting AST with the given input. |
| 16 | func ExecuteSelector(ctx context.Context, selectorStr string, value *model.Value, opts *Options) (*model.Value, error) { |
| 17 | if selectorStr == "" { |
| 18 | return value, nil |
| 19 | } |
| 20 | |
| 21 | expr, err := selector.Parse(selectorStr) |
| 22 | if err != nil { |
| 23 | return nil, fmt.Errorf("error parsing selector: %w", err) |
| 24 | } |
| 25 | |
| 26 | res, err := ExecuteAST(ctx, expr, value, opts) |
| 27 | if err != nil { |
| 28 | return nil, fmt.Errorf("error executing selector: %w", err) |
| 29 | } |
| 30 | |
| 31 | return res, nil |
| 32 | } |
| 33 | |
| 34 | type expressionExecutor func(ctx context.Context, options *Options, data *model.Value) (*model.Value, error) |
| 35 |