From 658a4bbb1eb4805c5319b6d011435f4832acbe48 Mon Sep 17 00:00:00 2001 From: boyska Date: Wed, 26 Dec 2018 01:29:39 +0100 Subject: [PATCH] filtering can be disabled with -tags nofilter it will make your binaries way smaller --- cmd/circolog-tail/main.go | 2 +- filtering/filter.go | 22 ++++++++++++---------- filtering/filter_fake.go | 17 +++++++++++++++++ hub.go | 2 +- 4 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 filtering/filter_fake.go diff --git a/cmd/circolog-tail/main.go b/cmd/circolog-tail/main.go index 67c7d21..41bc920 100644 --- a/cmd/circolog-tail/main.go +++ b/cmd/circolog-tail/main.go @@ -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 { diff --git a/filtering/filter.go b/filtering/filter.go index 3025ce8..0deebed 100644 --- a/filtering/filter.go +++ b/filtering/filter.go @@ -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 "" } } 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 } diff --git a/filtering/filter_fake.go b/filtering/filter_fake.go new file mode 100644 index 0000000..223b1b8 --- /dev/null +++ b/filtering/filter_fake.go @@ -0,0 +1,17 @@ +// +build nofilter + +package filtering + +type ExprValue struct { +} + +func (e *ExprValue) String() string { + return "" +} + +func (e *ExprValue) Set(value string) error { + return nil +} +func (e *ExprValue) Validate(line map[string]interface{}) bool { + return true +} diff --git a/hub.go b/hub.go index 058831a..15d9da7 100644 --- a/hub.go +++ b/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 {