Documentation ¶
Index ¶
- Constants
- type Entry
- type Error
- type Object
- func (o Object) Get(key string) Object
- func (o Object) GetEntries() []Entry
- func (o Object) GetError() error
- func (o Object) GetIndex(index int) Object
- func (o Object) GetKeys() []string
- func (o Object) GetValues() []Object
- func (o Object) IsBool() bool
- func (o Object) IsBoolStrict() bool
- func (o Object) IsEmpty() bool
- func (o Object) IsExists() bool
- func (o Object) IsFloat() bool
- func (o Object) IsFloatStrict() bool
- func (o Object) IsInt() bool
- func (o Object) IsIntStrict() bool
- func (o Object) IsMap() bool
- func (o Object) IsNil() bool
- func (o Object) IsSlice() bool
- func (o Object) IsString() bool
- func (o Object) IsStringStrict() bool
Examples ¶
Constants ¶
const ( ErrorObjectNotExists = "object isn't exists" ErrorTypeNotSupport = "type isn't supporting" ErrorFieldNotFound = "field name not found" ErrorIndexParse = "index can't be parsed" ErrorIndexRange = "index out of range" ErrorDataParse = "data can't be parsed" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Entry ¶
Entry - object that represents a key-value pair for such methods like GetEntries, ForEach, Map, etc.
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error - objects manipulation error
type Object ¶
type Object struct {
// contains filtered or unexported fields
}
Object - type of anything.
func NewFromBson ¶
NewFromBson - create new object from bson bytes
func NewFromData ¶
NewFromData - detect and create object from any supporting data format. It's supports JSON, YAML, TOML and BSON. XML and HTML isn't supporting, so it has extra fields which isn't straight data containers (like tags and attrs). Use your favourite XML/HTML deserializer and pass the result to New.
func NewFromJson ¶
NewFromJson - create new object from json bytes
func NewFromToml ¶
NewFromToml - create new object from toml bytes
func NewFromValue ¶
NewFromValue - create new object from reflect.Value
func NewFromYaml ¶
NewFromYaml - create new object from yaml bytes
func (Object) Get ¶
Get - get sub-object by their key-name. Can be applied to reflect.Map and reflect.Slice kinds. Acts like GetIndex if Object is reflect.Slice.
Example ¶
//source := `{ // "a": "value", // "b": { // "c": -500.5 // }, // "d": [3, 2, 1] //}` //var document interface{} //_ = json.Unmarshal([]byte(source), &document) //object := New(document) // //object.Get("a").String() // "value"
Output:
func (Object) GetEntries ¶
GetEntries - get key-values of reflect.Map or reflect.Slice. For reflect.Map order of entries is not guaranteeing.
func (Object) GetKeys ¶
GetKeys - get keys names of reflect.Map or indexes for reflect.Slice. For reflect.Map order of keys is not guaranteeing.
func (Object) GetValues ¶
GetValues - get values of reflect.Map or reflect.Slice. For reflect.Map order of values is not guaranteeing.
func (Object) IsBool ¶
IsBool - check that the object is boolean or can be cast. For string truthy values are: "true", "yes", "on" and if it can be cast to number - any except zero. For numbers truthy values any except zero. TODO: Make the realisation and tests
func (Object) IsBoolStrict ¶
IsBoolStrict - check that the object is boolean.
func (Object) IsEmpty ¶
IsEmpty - check that the object value empty. reflect.Array isn't contain any elements and reflect.Struct isn't contain any fields. Other types is equal their default values.
func (Object) IsFloatStrict ¶
IsFloatStrict - check that the object is float number.
func (Object) IsIntStrict ¶
IsIntStrict - check that the object is integer number.
func (Object) IsString ¶
IsString - check that the object is string or can be cast. Simple types like numbers always can be cast. If you would like to get something more complicated - use ToJson or similar serialization. If the required type serialization isn't presented - use ToValue and pass it to your favourite serializer manually.
func (Object) IsStringStrict ¶
IsStringStrict - check that the object is string.