diff options
Diffstat (limited to 'skate/map.go')
| -rw-r--r-- | skate/map.go | 35 | 
1 files changed, 4 insertions, 31 deletions
| diff --git a/skate/map.go b/skate/map.go index 5584371..9d3c98d 100644 --- a/skate/map.go +++ b/skate/map.go @@ -5,10 +5,10 @@ import (  	"errors"  	"reflect"  	"runtime" -	"strconv"  	"strings"  	json "github.com/segmentio/encoding/json" +	"github.com/tidwall/gjson"  )  var ( @@ -47,7 +47,7 @@ func (f Mapper) AsTSV(p []byte) ([]byte, error) {  	if err != nil {  		return nil, err  	} -	return append(bytes.Join(fields, bTab), bNewline...), nil +	return bytes.Join(fields, bTab), nil  }  // WithPrefix adds a given prefix to the first element. @@ -84,36 +84,9 @@ func Identity(p []byte) ([][]byte, error) {  // CreateFixedMapper extract the value from a given fixed top level json key.  // Returns a function that maps doc to (v, doc).  func CreateFixedMapper(field string) Mapper { -	if field == "" { -		return func(p []byte) ([][]byte, error) { -			return nil, ErrMissingFieldName -		} -	}  	f := func(p []byte) ([][]byte, error) { -		var ( -			doc map[string]interface{} -			v   interface{} -			ok  bool -			key []byte -		) -		if err := json.Unmarshal(p, &doc); err != nil { -			return nil, err -		} -		if v, ok = doc[field]; !ok { -			return nil, nil -		} -		switch w := v.(type) { -		case string: -			key = []byte(w) -		case int: -			key = []byte(strconv.Itoa(w)) -		case int64: -			key = []byte(strconv.Itoa(int(w))) -		case float64: -			key = []byte(strconv.FormatFloat(w, 'f', 52, 64)) -		default: -			return nil, nil -		} +		result := gjson.GetBytes(p, field) +		key := []byte(result.String())  		return [][]byte{key, p}, nil  	}  	return f | 
