Documentation
¶
Index ¶
- type OrderedMap
- func (om *OrderedMap) Delete(key string)
- func (om *OrderedMap) DeleteAt(offset int)
- func (om *OrderedMap) Exists(key string) (ok bool)
- func (om *OrderedMap) Filter(f func(key string, value interface{}) bool) *OrderedMap
- func (om *OrderedMap) Get(key string) (interface{}, bool)
- func (om *OrderedMap) GetAt(pos int) (val interface{}, ok bool)
- func (om *OrderedMap) Index(key string) int
- func (om *OrderedMap) Keys() []string
- func (om *OrderedMap) Len() int
- func (om *OrderedMap) Less(i, j int) bool
- func (om OrderedMap) MarshalJSON() ([]byte, error)
- func (om *OrderedMap) Reverse() *OrderedMap
- func (om *OrderedMap) Set(key string, value interface{})
- func (om *OrderedMap) SetAt(index int, key string, val interface{})
- func (om *OrderedMap) Sort()
- func (om *OrderedMap) String() string
- func (om *OrderedMap) Swap(i, j int)
- func (om *OrderedMap) UnmarshalJSON(b []byte) error
- func (om *OrderedMap) Values() []interface{}
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type OrderedMap ¶
type OrderedMap struct {
// contains filtered or unexported fields
}
An OrderedMap is a map where the keys keep the order that they're added. It is similar to indexed arrays. You can get the strings by key or by position. The OrderedMap is not safe for concurrent use.
func (*OrderedMap) Delete ¶
func (om *OrderedMap) Delete(key string)
Delete remove an item from the map by the supplied key. If the key does not exist, nothing happens.
func (*OrderedMap) DeleteAt ¶
func (om *OrderedMap) DeleteAt(offset int)
DeleteAt delete the key/value pair from the map by the supplied offset. If the offset is outside the range of the ordered map, nothing happens.
func (*OrderedMap) Exists ¶
func (om *OrderedMap) Exists(key string) (ok bool)
Exists test whether the key exists or not.
func (*OrderedMap) Filter ¶
func (om *OrderedMap) Filter(f func(key string, value interface{}) bool) *OrderedMap
Filter filters an OrderedMap if the provided function return true. Returns a new OrderedMap.
func (*OrderedMap) Get ¶
func (om *OrderedMap) Get(key string) (interface{}, bool)
Get returns the value of the map based on its key. It will return nil if it doesn't exist.
func (*OrderedMap) GetAt ¶
func (om *OrderedMap) GetAt(pos int) (val interface{}, ok bool)
GetAt returns the value based on the provided pos.
func (*OrderedMap) Index ¶
func (om *OrderedMap) Index(key string) int
Index returns the offset of the key in the ordered map. If the key could not be found, -1 is returned.
func (*OrderedMap) Keys ¶
func (om *OrderedMap) Keys() []string
Keys return the keys of the map in the order they were added.
func (*OrderedMap) Len ¶
func (om *OrderedMap) Len() int
Blelow three functions implement sort.Interface. Len returns the length of the map.
func (*OrderedMap) Less ¶
func (om *OrderedMap) Less(i, j int) bool
func (OrderedMap) MarshalJSON ¶
func (om OrderedMap) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaller interface, so it could be serialized. When serializing, the keys of the map will keep the order they are added.
func (*OrderedMap) Reverse ¶
func (om *OrderedMap) Reverse() *OrderedMap
Reverse reverse key & value of a map. The value must be a string. Returns a new OrderedMap.
func (*OrderedMap) Set ¶
func (om *OrderedMap) Set(key string, value interface{})
Set sets the key/value of the map based on key and value. If the value already exists, the value will be replaced.
func (*OrderedMap) SetAt ¶
func (om *OrderedMap) SetAt(index int, key string, val interface{})
SetAt sets the given key to the given value at the specified index. 1. If (index == -1 || index >= len(orderedmap)), then put it at the end. 2. If index is negative, index < -len(orderedmap), then put it at the beginning. 3 If index == -1, -2, ..., put it from the last, last - 1, etc...
func (*OrderedMap) String ¶
func (om *OrderedMap) String() string
String returns the JSON serialized string representation.
func (*OrderedMap) Swap ¶
func (om *OrderedMap) Swap(i, j int)
func (*OrderedMap) UnmarshalJSON ¶
func (om *OrderedMap) UnmarshalJSON(b []byte) error
UnmarshalJSON implements the json.Unmarshaller interface. so it could be use like below:
o := New() err := json.Unmarshal([]byte(jsonString), &o)
func (*OrderedMap) Values ¶
func (om *OrderedMap) Values() []interface{}
Values returns a slice of the values in the order they were added.