From a8bd8f39776f1c3d33a227d03ca00d27c4936987 Mon Sep 17 00:00:00 2001 From: flarezuo Date: Wed, 13 Feb 2019 15:35:55 +0800 Subject: [PATCH 1/2] [ADD] bound type filter --- filters.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/filters.go b/filters.go index b98857e6..75bef4a7 100644 --- a/filters.go +++ b/filters.go @@ -1,15 +1,39 @@ package godruid +import "errors" + type Filter struct { Type string `json:"type"` Dimension string `json:"dimension,omitempty"` Value interface{} `json:"value,omitempty"` + Lower string `json:"lower,omitempty"` + Upper string `json:"upper,omitempty"` Pattern string `json:"pattern,omitempty"` Function string `json:"function,omitempty"` Field *Filter `json:"field,omitempty"` Fields []*Filter `json:"fields,omitempty"` } +func FilterBound(dimension string, bonds ...string) *Filter { + var lower string + var upper string + + if len(bonds) < 1 || len(bonds) > 2 { + errors.New("lower and upper should be setted with 1 ~ 2 values") + } else { + lower = bonds[0] + if len(bonds) > 1 { + upper = bonds[1] + } + } + return &Filter{ + Type: "bound", + Dimension: dimension, + Lower: lower, + Upper: upper, + } +} + func FilterSelector(dimension string, value interface{}) *Filter { return &Filter{ Type: "selector", From be60500ec918882e89cf64d2f83f62134d56b75e Mon Sep 17 00:00:00 2001 From: flarezuo Date: Thu, 14 Feb 2019 17:59:52 +0800 Subject: [PATCH 2/2] [OPT] always return --- filters.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/filters.go b/filters.go index 75bef4a7..2a4fcce3 100644 --- a/filters.go +++ b/filters.go @@ -1,7 +1,5 @@ package godruid -import "errors" - type Filter struct { Type string `json:"type"` Dimension string `json:"dimension,omitempty"` @@ -18,9 +16,7 @@ func FilterBound(dimension string, bonds ...string) *Filter { var lower string var upper string - if len(bonds) < 1 || len(bonds) > 2 { - errors.New("lower and upper should be setted with 1 ~ 2 values") - } else { + if len(bonds) >= 1 && len(bonds) <= 2 { lower = bonds[0] if len(bonds) > 1 { upper = bonds[1]