github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/jsonparserw/jsonparserw.go (about) 1 package jsonparserw 2 3 import ( 4 "fmt" 5 6 "github.com/buger/jsonparser" 7 "github.com/pkg/errors" 8 ) 9 10 func wrapError(keys []string, err error) error { 11 return errors.Wrap(err, fmt.Sprintf("jsonparserw error with keys %v", keys)) 12 } 13 14 func ArrayEach(data []byte, cb func(value []byte, dataType jsonparser.ValueType, offset int, err error), keys ...string) (offset int, err error) { 15 offset, err = jsonparser.ArrayEach(data, cb, keys...) 16 return offset, wrapError(keys, err) 17 } 18 19 func GetBoolean(data []byte, keys ...string) (val bool, err error) { 20 val, err = jsonparser.GetBoolean(data, keys...) 21 return val, wrapError(keys, err) 22 } 23 24 func GetInt(data []byte, keys ...string) (val int64, err error) { 25 val, err = jsonparser.GetInt(data, keys...) 26 return val, wrapError(keys, err) 27 } 28 29 func GetString(data []byte, keys ...string) (val string, err error) { 30 val, err = jsonparser.GetString(data, keys...) 31 return val, wrapError(keys, err) 32 } 33 34 func Get(data []byte, keys ...string) (value []byte, dataType jsonparser.ValueType, offset int, err error) { 35 value, dataType, offset, err = jsonparser.Get(data, keys...) 36 return value, dataType, offset, wrapError(keys, err) 37 }