EvalSearchInput checks if its input is JSON. If so it returns a Constraint constructed from that JSON. Otherwise it assumes the input to be a search expression. It parses the expression and returns the parsed Constraint.
(in string)
| 932 | // EvalSearchInput checks if its input is JSON. If so it returns a Constraint constructed from that JSON. Otherwise |
| 933 | // it assumes the input to be a search expression. It parses the expression and returns the parsed Constraint. |
| 934 | func evalSearchInput(in string) (*Constraint, error) { |
| 935 | if len(in) == 0 { |
| 936 | return nil, fmt.Errorf("empty expression") |
| 937 | } |
| 938 | if strings.HasPrefix(in, "{") && strings.HasSuffix(in, "}") { |
| 939 | cs := new(Constraint) |
| 940 | if err := json.NewDecoder(strings.NewReader(in)).Decode(&cs); err != nil { |
| 941 | return nil, err |
| 942 | } |
| 943 | return cs, nil |
| 944 | } else { |
| 945 | sq, err := parseExpression(context.TODO(), in) |
| 946 | if err != nil { |
| 947 | return nil, err |
| 948 | } |
| 949 | return sq.Constraint.Logical.B, nil |
| 950 | } |
| 951 | } |
| 952 | |
| 953 | // getNamed displays the search expression or constraint json for the requested alias. |
| 954 | func (h *Handler) getNamed(ctx context.Context, name string) (string, error) { |
no test coverage detected