-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.md.tpl
58 lines (47 loc) · 1.38 KB
/
README.md.tpl
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
47
48
49
50
51
52
53
54
55
56
57
# Qualify!
[](https://travis-ci.org/bsm/qualify)
[](http://godoc.org/github.com/bsm/qualify)
[](https://goreportcard.com/report/github.com/bsm/qualify)
[](https://opensource.org/licenses/Apache-2.0)
Library for fast rules evaluation for Go. Qualify is able to quickly match a fact against large number of pre-defined rules.
### Example:
```go
import (
"fmt"
"github.com/bsm/qualify"
)
// Fact is an example fact
type Fact struct {
Country string
Browser string
OS string
Attrs []int
}
// Enumeration of our fact features
const (
FieldCountry qualify.Field = iota
FieldBrowser
FieldOS
FieldAttrs
)
// factReader is a wrapper around facts to
// make them comply with qualify.Fact
type factReader struct {
Dict qualify.StrDict
Fact
}
func (r *factReader) AppendFieldValues(x []int, f qualify.Field) []int {
switch f {
case FieldCountry:
return r.Dict.Lookup(x, r.Country)
case FieldBrowser:
return r.Dict.Lookup(x, r.Browser)
case FieldOS:
return r.Dict.Lookup(x, r.OS)
case FieldAttrs:
return append(x, r.Attrs...)
}
return x
}
func main() {{ "ExampleQualifier" | code }}
```