Documentation
¶
Overview ¶
Package dproxy provides a proxy to adccess `interface{}` (document) by simple query. It is intended to be used with `"encoding/json".Unmarshal()` or so.
Index ¶
- type Drain
- func (d *Drain) All() []error
- func (d *Drain) Array(p Proxy) []interface{}
- func (d *Drain) ArrayArray(ps ProxySet) [][]interface{}
- func (d *Drain) Bool(p Proxy) bool
- func (d *Drain) BoolArray(ps ProxySet) []bool
- func (d *Drain) CombineErrors() error
- func (d *Drain) First() error
- func (d *Drain) Float64(p Proxy) float64
- func (d *Drain) Float64Array(ps ProxySet) []float64
- func (d *Drain) Has() bool
- func (d *Drain) Int64(p Proxy) int64
- func (d *Drain) Int64Array(ps ProxySet) []int64
- func (d *Drain) Map(p Proxy) map[string]interface{}
- func (d *Drain) MapArray(ps ProxySet) []map[string]interface{}
- func (d *Drain) ProxyArray(ps ProxySet) []Proxy
- func (d *Drain) String(p Proxy) string
- func (d *Drain) StringArray(ps ProxySet) []string
- type Error
- type ErrorType
- type Proxy
- type ProxySet
- type Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Drain ¶ added in v1.2.0
type Drain struct {
// contains filtered or unexported fields
}
Drain stores errors from Proxy or ProxySet.
func (*Drain) All ¶ added in v1.2.0
All returns all errors which stored. Return nil if no errors stored.
func (*Drain) ArrayArray ¶ added in v1.2.0
ArrayArray returns [][]interface{} value and stores an error.
func (*Drain) CombineErrors ¶ added in v1.2.0
CombineErrors returns an error which combined all stored errors. Return nil if not erros stored.
func (*Drain) First ¶ added in v1.2.0
First returns a stored error. Returns nil if there are no errors.
func (*Drain) Float64Array ¶ added in v1.2.0
Float64Array returns []float64 value and stores an error.
func (*Drain) Int64Array ¶ added in v1.2.0
Int64Array returns []int64 value and stores an error.
func (*Drain) MapArray ¶ added in v1.2.0
MapArray returns []map[string]interface{} value and stores an error.
func (*Drain) ProxyArray ¶ added in v1.2.0
ProxyArray returns []Proxy value and stores an error.
func (*Drain) StringArray ¶ added in v1.2.0
StringArray returns []string value and stores an error.
type Error ¶
type Error interface {
// ErrorType returns type of error.
ErrorType() ErrorType
// FullAddress returns query string where cause first error.
FullAddress() string
}
Error get detail information of the errror.
type ErrorType ¶
type ErrorType int
ErrorType is type of errors
const ( // Etype means expected type is not matched with actual. Etype ErrorType = iota + 1 // Enotfound means key or index doesn't exist. Enotfound // EmapNorArray means target is not a map nor an array (for JSON Pointer) EmapNorArray // EconvertFailure means value conversion is failed. EconvertFailure // EinvalidIndex means token is invalid as index (for JSON Pointer) EinvalidIndex // EinvalidQuery means query is invalid as JSON Pointer. EinvalidQuery // ErequiredType means the type mismatch against user required one. // For example M() requires map, A() requires array. ErequiredType )
type Proxy ¶
type Proxy interface {
// Nil returns true, if target value is nil.
Nil() bool
// Value returns a proxied value. If there are no values, it returns
// error.
Value() (interface{}, error)
// Bool returns its value. If value isn't the type, it returns error.
Bool() (bool, error)
// Int64 returns its value. If value isn't the type, it returns error.
Int64() (int64, error)
// Float64 returns its value. If value isn't the type, it returns error.
Float64() (float64, error)
// String returns its value. If value isn't the type, it returns error.
String() (string, error)
// Array returns its value. If value isn't the type, it returns error.
Array() ([]interface{}, error)
// Map returns its value. If value isn't the type, it returns error.
Map() (map[string]interface{}, error)
// A returns an item from value treated as the array.
A(n int) Proxy
// M returns an item from value treated as the map.
M(k string) Proxy
// P returns which pointed by JSON Pointer's query q.
P(q string) Proxy
// ProxySet returns a set which converted from its array value.
ProxySet() ProxySet
// Q returns set of all items which property matchs with k.
Q(k string) ProxySet
// contains filtered or unexported methods
}
Proxy is a proxy to access a document (interface{}).
type ProxySet ¶ added in v1.2.0
type ProxySet interface {
// Empty returns true when the set is empty.
Empty() bool
// Len returns count of items in the set.
Len() int
// BoolArray returns []bool which converterd from the set.
BoolArray() ([]bool, error)
// Int64Array returns []int64 which converterd from the set.
Int64Array() ([]int64, error)
// Float64Array returns []float64 which converterd from the set.
Float64Array() ([]float64, error)
// StringArray returns []string which converterd from the set.
StringArray() ([]string, error)
// ArrayArray returns [][]interface{} which converterd from the set.
ArrayArray() ([][]interface{}, error)
// MapArray returns []map[string]interface{} which converterd from the set.
MapArray() ([]map[string]interface{}, error)
// ProxyArray returns []Proxy which wrap each items.
ProxyArray() ([]Proxy, error)
// A returns an proxy for index in the set.
A(n int) Proxy
// Q returns set of all items which property matchs with k.
Q(k string) ProxySet
// Qc returns set of property of all items.
Qc(k string) ProxySet
// contains filtered or unexported methods
}
ProxySet proxies to access to set.
type Type ¶
type Type int
Type is type of value.
const ( // Tunknown shows value is not supported. Tunknown Type = iota // Tnil shows value is nil. Tnil // Tbool shows value is bool. Tbool // Tint64 shows value is int64. Tint64 // Tfloat64 shows value is float64. Tfloat64 // Tstring shows value is string. Tstring // Tarray shows value is an array ([]interface{}) Tarray // Tmap shows value is a map (map[string]interface{}) Tmap )