blob: 637794478227d2431da84c4543536e244191fb05 (
plain)
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
|
package filter
import (
"github.com/Necoro/gofeed"
"github.com/antonmedv/expr"
"github.com/antonmedv/expr/vm"
)
type Filter struct {
prog *vm.Program
}
func (f *Filter) Run(item *gofeed.Item) (bool, error) {
if res, err := expr.Run(f.prog, item); err != nil {
return false, err
} else {
return res.(bool), nil
}
}
func New(s string) (*Filter, error) {
prog, err := expr.Compile(s, expr.AsBool(), expr.Env(gofeed.Item{}))
if err != nil {
return nil, err
}
return &Filter{prog}, nil
}
|