Skip to content

Commit

Permalink
Remove gojq dep from aggr package
Browse files Browse the repository at this point in the history
  • Loading branch information
rs committed Mar 9, 2018
1 parent cb27111 commit 2ebde03
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions aggr/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"fmt"
"strings"
"sync"

"github.com/elgs/gojq"
)

// Field describe an aggregation on a field.
Expand All @@ -22,6 +20,11 @@ type Fields struct {
mu sync.Mutex
}

// Querier is used to query data using JSON path.
type Querier interface {
Query(exp string) (interface{}, error)
}

// NewFields parses defs and create aggregation fields.
func NewFields(defs []string) (*Fields, error) {
fields := make([]Field, 0, len(defs))
Expand All @@ -36,11 +39,11 @@ func NewFields(defs []string) (*Fields, error) {
}

// Push pushes new pre-parsed JSON data to the aggregations.
func (fs *Fields) Push(jq *gojq.JQ) error {
func (fs *Fields) Push(q Querier) error {
fs.mu.Lock()
defer fs.mu.Unlock()
for _, f := range fs.f {
if err := f.Push(jq); err != nil {
if err := f.Push(q); err != nil {
return err
}
}
Expand Down Expand Up @@ -94,8 +97,8 @@ func NewField(def string) (Field, error) {
}

// Push pushes new pre-parsed JSON data to the aggregations.
func (f *Field) Push(jq *gojq.JQ) error {
v, err := jq.Query(f.Path)
func (f *Field) Push(q Querier) error {
v, err := q.Query(f.Path)
if err != nil {
return err
}
Expand Down

0 comments on commit 2ebde03

Please sign in to comment.