-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathop.go
46 lines (40 loc) · 1.17 KB
/
op.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright 2013 The lime Authors.
// Use of this source code is governed by a 2-clause
// BSD-style license that can be found in the LICENSE file.
package util
import (
"encoding/json"
)
type (
// A comparison operation used in context queries.
Op int
)
const (
OpEqual Op = iota //< Compare for equality.
OpNotEqual //< Compare for difference.
OpRegexMatch //< Compare for a regular expression match.
OpNotRegexMatch //< Compare for a regular expression difference.
OpRegexContains //< Compare whether the given regular expression matches some substring of the operand.
OpNotRegexContains //< Compare whether the given regular expression does not match some substring of the operand.
)
func (o *Op) UnmarshalJSON(d []byte) error {
var tmp string
if err := json.Unmarshal(d, &tmp); err != nil {
return err
}
switch tmp {
default:
*o = OpEqual
case "not_equal":
*o = OpNotEqual
case "regex_match":
*o = OpRegexMatch
case "not_regex_match":
*o = OpNotRegexMatch
case "regex_contains":
*o = OpRegexContains
case "not_regex_contains":
*o = OpNotRegexContains
}
return nil
}