Documentation ¶
Overview ¶
Package ordered provided a type OrderedMap for use in JSON handling
Index ¶
- type KVPair
- type OrderedMap
- func (om *OrderedMap) Delete(key string) (value interface{}, ok bool)
- func (om *OrderedMap) EntriesIter() func() (*KVPair, bool)
- func (om *OrderedMap) EntriesReverseIter() func() (*KVPair, bool)
- func (om *OrderedMap) Get(key string) interface{}
- func (om *OrderedMap) GetValue(key string) (value interface{}, ok bool)
- func (om *OrderedMap) Has(key string) bool
- func (om *OrderedMap) Len() int
- func (om *OrderedMap) MarshalJSON() (res []byte, err error)
- func (om *OrderedMap) Set(key string, value interface{})
- func (om *OrderedMap) UnmarshalJSON(data []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type KVPair ¶
type KVPair struct { Key string Value interface{} }
the key-value pair type, for initializing from a list of key-value pairs, or for looping entries in the same order
type OrderedMap ¶
type OrderedMap struct {
// contains filtered or unexported fields
}
the OrderedMap type, has similar operations as the default map, but maintained the keys order of inserted; similar to map, all single key operations (Get/Set/Delete) runs at O(1).
func NewOrderedMapFromKVPairs ¶
func NewOrderedMapFromKVPairs(pairs []*KVPair) *OrderedMap
Create a new OrderedMap and populate from a list of key-value pairs
func (*OrderedMap) Delete ¶
func (om *OrderedMap) Delete(key string) (value interface{}, ok bool)
deletes the element with the specified key (m[key]) from the map. If there is no such element, this is a no-op.
func (*OrderedMap) EntriesIter ¶
func (om *OrderedMap) EntriesIter() func() (*KVPair, bool)
Iterate all key/value pairs in the same order of object constructed
func (*OrderedMap) EntriesReverseIter ¶
func (om *OrderedMap) EntriesReverseIter() func() (*KVPair, bool)
Iterate all key/value pairs in the reverse order of object constructed
func (*OrderedMap) Get ¶
func (om *OrderedMap) Get(key string) interface{}
Get value for particular key, or nil if not exist; but don't rely on nil for non-exist; should check by Has or GetValue
func (*OrderedMap) GetValue ¶
func (om *OrderedMap) GetValue(key string) (value interface{}, ok bool)
Get value and exists together
func (*OrderedMap) MarshalJSON ¶
func (om *OrderedMap) MarshalJSON() (res []byte, err error)
this implements type json.Marshaler interface, so can be called in json.Marshal(om)
func (*OrderedMap) Set ¶
func (om *OrderedMap) Set(key string, value interface{})
set value for particular key, this will remember the order of keys inserted but if the key already exists, the order is not updated.
func (*OrderedMap) UnmarshalJSON ¶
func (om *OrderedMap) UnmarshalJSON(data []byte) error
this implements type json.Unmarshaler interface, so can be called in json.Unmarshal(data, om)