filtering can be disabled with -tags nofilter
it will make your binaries way smaller
This commit is contained in:
parent
14e97dd43e
commit
658a4bbb1e
4 changed files with 31 additions and 12 deletions
|
@ -75,7 +75,7 @@ func main() {
|
|||
log.Println("invalid BSON", err)
|
||||
continue
|
||||
}
|
||||
if filter.Node != nil && !filter.Validate(parsed) {
|
||||
if !filter.Validate(parsed) {
|
||||
continue
|
||||
}
|
||||
if err := formatter.WriteFormatted(os.Stdout, formatter.FormatSyslog, parsed); err != nil {
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// +build !nofilter
|
||||
|
||||
package filtering
|
||||
|
||||
import (
|
||||
|
@ -11,38 +13,38 @@ import (
|
|||
)
|
||||
|
||||
type ExprValue struct {
|
||||
Node expr.Node
|
||||
Expression string
|
||||
node expr.Node
|
||||
expression string
|
||||
}
|
||||
|
||||
func (e *ExprValue) String() string {
|
||||
if e.Node != nil {
|
||||
return e.Node.String()
|
||||
if e.node != nil {
|
||||
return e.node.String()
|
||||
} else {
|
||||
return "<Empty Expression>"
|
||||
}
|
||||
}
|
||||
func (e *ExprValue) Set(value string) error {
|
||||
if value == "" {
|
||||
e.Node = nil
|
||||
e.Expression = value
|
||||
e.node = nil
|
||||
e.expression = value
|
||||
return nil
|
||||
}
|
||||
ast, err := expr.ParseExpression(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
e.Node = ast
|
||||
e.Expression = value
|
||||
e.node = ast
|
||||
e.expression = value
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *ExprValue) Validate(line map[string]interface{}) bool {
|
||||
if e.Node == nil {
|
||||
if e.node == nil {
|
||||
return true
|
||||
}
|
||||
context := datasource.NewContextSimpleNative(line)
|
||||
val, ok := vm.Eval(context, e.Node)
|
||||
val, ok := vm.Eval(context, e.node)
|
||||
if !ok || val == nil { // errors when evaluating
|
||||
return false
|
||||
}
|
||||
|
|
17
filtering/filter_fake.go
Normal file
17
filtering/filter_fake.go
Normal file
|
@ -0,0 +1,17 @@
|
|||
// +build nofilter
|
||||
|
||||
package filtering
|
||||
|
||||
type ExprValue struct {
|
||||
}
|
||||
|
||||
func (e *ExprValue) String() string {
|
||||
return "<filtering disabled>"
|
||||
}
|
||||
|
||||
func (e *ExprValue) Set(value string) error {
|
||||
return nil
|
||||
}
|
||||
func (e *ExprValue) Validate(line map[string]interface{}) bool {
|
||||
return true
|
||||
}
|
2
hub.go
2
hub.go
|
@ -144,7 +144,7 @@ func (h *Hub) Run() {
|
|||
cmd.Response <- CommandResponse{Value: map[string]interface{}{
|
||||
"size": h.circbuf.Len(),
|
||||
"paused": !active,
|
||||
"filter": filter.Expression,
|
||||
"filter": filter.String(),
|
||||
}}
|
||||
case CommandNewFilter:
|
||||
if err := filter.Set(cmd.Parameters["where"].(string)); err != nil {
|
||||
|
|
Loading…
Reference in a new issue