Documentation
¶
Overview ¶
Package ggja—the Go Generic JSON Api—is a small helper library to make working with Go's generic JSON types more comfortable.
Index ¶
- func Get(v interface{}, path ...interface{}) (interface{}, error)
- func GetString(v interface{}, path ...interface{}) (string, error)
- func Recover(err *error)
- type Arr
- func (a *Arr) Arr(idx int) *Arr
- func (a *Arr) Bool(idx int, nvl bool) bool
- func (a *Arr) CArr(idx int) (elm *Arr)
- func (a *Arr) CObj(idx int) (elm *Obj)
- func (a *Arr) F32(idx int, nvl float32) float32
- func (a *Arr) F64(idx int, nvl float64) float64
- func (a *Arr) Ignoring(errs ...error) *Arr
- func (a *Arr) Int(idx int, nvl int) int
- func (a *Arr) Len() int
- func (a *Arr) MArr(idx int) *Arr
- func (a *Arr) MBool(idx int) bool
- func (a *Arr) MF32(idx int) float32
- func (a *Arr) MF64(idx int) float64
- func (a *Arr) MInt(idx int) int
- func (a *Arr) MObj(idx int) *Obj
- func (a *Arr) MStr(idx int) string
- func (a *Arr) MUint32(idx int) uint32
- func (a *Arr) Obj(idx int) *Obj
- func (a *Arr) Put(idx int, v interface{}) *Arr
- func (a *Arr) Set(idx int, v interface{}) *Arr
- func (a *Arr) Str(idx int, nvl string) string
- func (a *Arr) Uint32(idx int, nvl uint32) uint32
- type BareArr
- type BareObj
- type IdxRangeError
- type IgnoreErrors
- type IndexError
- type KeyError
- type NoConversionError
- type Obj
- func (o *Obj) Arr(key string) *Arr
- func (o *Obj) Bool(key string, nvl bool) bool
- func (o *Obj) CArr(key string) (sub *Arr)
- func (o *Obj) CObj(key string) (sub *Obj)
- func (o *Obj) F32(key string, nvl float32) float32
- func (o *Obj) F64(key string, nvl float64) float64
- func (o *Obj) Ignoring(errs ...error) *Obj
- func (o *Obj) Int(key string, nvl int) int
- func (o *Obj) Int16(key string, nvl int16) int16
- func (o *Obj) Int32(key string, nvl int32) int32
- func (o *Obj) Int64(key string, nvl int64) int64
- func (o *Obj) Int8(key string, nvl int8) int8
- func (o *Obj) MArr(key string) *Arr
- func (o *Obj) MBool(key string) bool
- func (o *Obj) MF32(key string) float32
- func (o *Obj) MF64(key string) float64
- func (o *Obj) MInt(key string) int
- func (o *Obj) MInt16(key string) int16
- func (o *Obj) MInt32(key string) int32
- func (o *Obj) MInt64(key string) int64
- func (o *Obj) MInt8(key string) int8
- func (o *Obj) MObj(key string) (sub *Obj)
- func (o *Obj) MStr(key string) string
- func (o *Obj) MTime(key string) time.Time
- func (o *Obj) MUint16(key string) uint16
- func (o *Obj) MUint32(key string) uint32
- func (o *Obj) MUint64(key string) uint64
- func (o *Obj) MUint8(key string) uint8
- func (o *Obj) Obj(key string) (sub *Obj)
- func (o *Obj) Put(key string, v interface{}) *Obj
- func (o *Obj) Set(key string, v interface{}) *Obj
- func (o *Obj) Str(key, nvl string) string
- func (o *Obj) Time(key string, nvl time.Time) time.Time
- func (o *Obj) Uint16(key string, nvl uint16) uint16
- func (o *Obj) Uint32(key string, nvl uint32) uint32
- func (o *Obj) Uint64(key string, nvl uint64) uint64
- func (o *Obj) Uint8(key string, nvl uint8) uint8
- type SetError
- type TypeMismatch
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Get ¶ added in v0.10.1
func Get(v interface{}, path ...interface{}) (interface{}, error)
Example ¶
package main import ( "fmt" "math" "testing" ) func printError(err error) { fmt.Printf("ERROR: %s\n", err) } type onErr struct { t *testing.T } func (oe onErr) error(err error) { oe.t.Error(err) } func (oe onErr) fatal(err error) { oe.t.Fatal(err) } func main() { data := BareObj{ "foo": "bar", "baz": BareArr{ true, false, BareObj{"OK": math.Pi}, "end", }, } fmt.Println(Get(data, "baz", -2)) }
Output: map[OK:3.141592653589793] <nil>
Types ¶
type Arr ¶
type Arr struct { Bare BareArr // When OnError is nil all methods will panic on error, otherwise // OnError(err) will be called. 'M*' methods returing values will return // zero value on error if OnError has no non-local exists. Non-'M*' methods // retrun the nvl value. OnError func(error) }
func (*Arr) CObj ¶
Example ¶
ggjaArr := Arr{OnError: printError} objMbr3 := ggjaArr.CObj(3) objMbr3.Put("name", "John Doe") jStr, _ := json.Marshal(ggjaArr.Bare) fmt.Println(string(jStr)) jStr, _ = json.Marshal(objMbr3.Bare) fmt.Println(string(jStr))
Output: [null,null,null,{"name":"John Doe"}] {"name":"John Doe"}
type IdxRangeError ¶ added in v0.10.0
type IdxRangeError struct {
Begin, End int
}
func (IdxRangeError) Error ¶ added in v0.10.0
func (eir IdxRangeError) Error() string
type IgnoreErrors ¶ added in v0.10.0
func (IgnoreErrors) Error ¶ added in v0.10.0
func (ign IgnoreErrors) Error(err error)
type IndexError ¶ added in v0.10.0
type IndexError struct {
Idx, EIdx int
// contains filtered or unexported fields
}
func (IndexError) Error ¶ added in v0.10.0
func (ee IndexError) Error() string
func (IndexError) Unwrap ¶ added in v0.10.0
func (ee IndexError) Unwrap() error
type KeyError ¶ added in v0.10.0
type KeyError struct { Key string // contains filtered or unexported fields }
type NoConversionError ¶ added in v0.10.1
type NoConversionError struct { Value interface{} Target string }
func (NoConversionError) Error ¶ added in v0.10.1
func (nce NoConversionError) Error() string
type Obj ¶
type Obj struct { Bare BareObj // When OnError is nil all methods will panic on error, otherwise // OnError(err) will be called. 'M*' methods returing values will return // zero value on error if OnError has no non-local exists. Non-'M*' methods // retrun the nvl value. OnError func(error) }
type TypeMismatch ¶ added in v0.10.0
type TypeMismatch struct { Expect string Value interface{} }
func (TypeMismatch) Error ¶ added in v0.10.0
func (tmm TypeMismatch) Error() string
Click to show internal directories.
Click to hide internal directories.