Documentation
¶
Index ¶
- Constants
- func CoerceFloat(v interface{}) (float64, error)
- func CoerceFloatShort(v interface{}) float64
- func CoerceInt(v interface{}) (int, error)
- func CoerceInt64(v interface{}) (int64, error)
- func CoerceInt64Short(v interface{}) int64
- func CoerceIntShort(v interface{}) int
- func CoerceString(v interface{}) (string, error)
- func CoerceStringShort(v interface{}) string
- func CoerceUint(v interface{}) (uint64, error)
- func CoerceUintShort(v interface{}) uint64
- func IsJson(by []byte) bool
- func IsJsonArray(by []byte) bool
- func IsJsonObject(by []byte) bool
- func JsonString(v interface{}) string
- func MakeJsonList(b []byte) []byte
- type JsonHelper
- func (j JsonHelper) Bool(n string, defVal bool) bool
- func (j JsonHelper) Float64(n string, defVal float64) float64
- func (j JsonHelper) Get(n string) interface{}
- func (j *JsonHelper) GobDecode(data []byte) error
- func (j *JsonHelper) GobEncode() ([]byte, error)
- func (j JsonHelper) HasKey(name string) bool
- func (j JsonHelper) Helper(n string) JsonHelper
- func (j JsonHelper) Helpers(n string) []JsonHelper
- func (j JsonHelper) Int(n string, defVal int) int
- func (j JsonHelper) Int64(n string, defVal int64) int64
- func (j JsonHelper) Ints(n string, defVal []int) []int
- func (j JsonHelper) Keys() []string
- func (j JsonHelper) List(n string, defVal []interface{}) []interface{}
- func (j JsonHelper) Map(n string, defVal map[string]interface{}) map[string]interface{}
- func (j JsonHelper) PrettyJson() []byte
- func (j JsonHelper) String(n string, defVal string) string
- func (j JsonHelper) Strings(n string, defVal []string) []string
- func (j JsonHelper) Uint64(n string, defVal uint64) uint64
- type JsonInterface
- func (j *JsonInterface) Encode() ([]byte, error)
- func (j *JsonInterface) Float() (float32, error)
- func (j JsonInterface) FloatSh() float32
- func (j *JsonInterface) Int() (int, error)
- func (j JsonInterface) IntSh() int
- func (j *JsonInterface) MarshalJSON() ([]byte, error)
- func (j *JsonInterface) String() (string, error)
- func (j JsonInterface) StringSh() string
- func (j *JsonInterface) UnmarshalJSON(raw []byte) error
- type JsonRawWriter
Constants ¶
const ( MaxInt = 1<<(BitsPerWord-1) - 1 // either 1<<31 - 1 or 1<<63 - 1 MinInt = -MaxInt - 1 // either -1 << 31 or -1 << 63 MaxUint = 1<<BitsPerWord - 1 // either 1<<32 - 1 or 1<<64 - 1 )
Implementation-specific integer limit values.
const BitsPerWord = bitsPerWord // either 32 or 64
Implementation-specific size of int and uint in bits.
Variables ¶
This section is empty.
Functions ¶
func CoerceFloat ¶
func CoerceFloatShort ¶
func CoerceFloatShort(v interface{}) float64
func CoerceInt64 ¶
func CoerceInt64Short ¶
func CoerceInt64Short(v interface{}) int64
func CoerceIntShort ¶
func CoerceIntShort(v interface{}) int
func CoerceString ¶
Coerce types (string,int,int64, float, []byte) into String type
func CoerceStringShort ¶
func CoerceStringShort(v interface{}) string
Coerce type to string, returning zero length string if error or nil
func CoerceUint ¶
Coerce a val(interface{}) into a Uint64
func CoerceUintShort ¶
func CoerceUintShort(v interface{}) uint64
Coerce a Val(interface{}) into Uint64
func IsJson ¶
Determines if the bytes is a json array, only looks at prefix
not parsing the entire thing
func IsJsonArray ¶
Determines if the bytes is a json array, only looks at prefix
not parsing the entire thing
func IsJsonObject ¶
func JsonString ¶
func JsonString(v interface{}) string
Types ¶
type JsonHelper ¶
type JsonHelper map[string]interface{}
A wrapper around a map[string]interface{} to facilitate coercion of json data to what you want
allows usage such as this
jh := NewJsonHelper([]byte(`{
"name":"string",
"ints":[1,5,9,11],
"int":1,
"int64":1234567890,
"MaxSize" : 1048576,
"strings":["string1"],
"nested":{
"nest":"string2",
"strings":["string1"],
"int":2,
"list":["value"],
"nest2":{
"test":"good"
}
},
"nested2":[
{"sub":5}
]
}`)
i := jh.Int("nested.int") // 2
i2 := jh.Int("ints[1]") // 5 array position 1 from [1,5,9,11]
s := jh.String("nested.nest") // "string2"
func NewJsonHelper ¶
func NewJsonHelper(b []byte) JsonHelper
func NewJsonHelperFromResp ¶
func NewJsonHelperFromResp(resp *http.Response) (JsonHelper, error)
Make a JsonHelper from http response. This will automatically close the response body
func NewJsonHelperReader ¶
func NewJsonHelperReader(r io.Reader) (jh JsonHelper, err error)
func NewJsonHelpers ¶
func NewJsonHelpers(b []byte) []JsonHelper
func (JsonHelper) Get ¶
func (j JsonHelper) Get(n string) interface{}
Get the key (or keypath) value as interface, mostly used internally through String, etc methods
jh.Get("name.subname")
jh.Get("name/subname")
jh.Get("name.arrayname[1]")
jh.Get("name.arrayname[]")
func (*JsonHelper) GobDecode ¶
func (j *JsonHelper) GobDecode(data []byte) error
GobDecode overwrites the receiver, which must be a pointer, with the value represented by the byte slice, which was written by GobEncode, usually for the same concrete type. GobDecode([]byte) error
func (*JsonHelper) GobEncode ¶
func (j *JsonHelper) GobEncode() ([]byte, error)
func (JsonHelper) HasKey ¶
func (j JsonHelper) HasKey(name string) bool
func (JsonHelper) Helper ¶
func (j JsonHelper) Helper(n string) JsonHelper
Get a Helper from a string path
func (JsonHelper) Helpers ¶
func (j JsonHelper) Helpers(n string) []JsonHelper
Get list of Helpers at given name. Trys to coerce into proper Helper type
func (JsonHelper) Keys ¶
func (j JsonHelper) Keys() []string
func (JsonHelper) List ¶
func (j JsonHelper) List(n string, defVal []interface{}) []interface{}
Gets slice of interface{}
func (JsonHelper) Map ¶
func (j JsonHelper) Map(n string, defVal map[string]interface{}) map[string]interface{}
func (JsonHelper) PrettyJson ¶
func (j JsonHelper) PrettyJson() []byte
type JsonInterface ¶
type JsonInterface struct {
// contains filtered or unexported fields
}
A simple wrapper to help json data be consumed when not using Strongly typed structs.
func (*JsonInterface) Encode ¶
func (j *JsonInterface) Encode() ([]byte, error)
Encode returns its marshaled data as `[]byte`
func (*JsonInterface) Float ¶
func (j *JsonInterface) Float() (float32, error)
Coerce to Float, return err if needed
func (JsonInterface) FloatSh ¶
func (j JsonInterface) FloatSh() float32
Coerce to Float, 0 returned if 0 or missing
func (JsonInterface) IntSh ¶
func (j JsonInterface) IntSh() int
Coerce to Int, 0 returned if missing or zero
func (*JsonInterface) MarshalJSON ¶
func (j *JsonInterface) MarshalJSON() ([]byte, error)
Implements the json.Marshaler interface.
func (JsonInterface) StringSh ¶
func (j JsonInterface) StringSh() string
Coerce to a string, may be zero length if missing, or zero length
func (*JsonInterface) UnmarshalJSON ¶
func (j *JsonInterface) UnmarshalJSON(raw []byte) error
Implements the json.Unmarshal interface.
type JsonRawWriter ¶
func (*JsonRawWriter) MarshalJSON ¶
func (m *JsonRawWriter) MarshalJSON() ([]byte, error)
func (*JsonRawWriter) Raw ¶
func (m *JsonRawWriter) Raw() json.RawMessage