Documentation ¶
Overview ¶
Package key_value defines the custom map and its additional functions.
The package defines two different data types:
- KeyValue is the map where the kv is a string, and the value could be anything. It defines additional functions that return the value converted to the desired type.
- List is the list of elements but based on the map. For the user, the list acts as the array. However, internally it uses a map for optimization.
Index ¶
- Constants
- type KeyValue
- func (k KeyValue) BigIntValue(key string) (*big.Int, error)
- func (k KeyValue) BoolValue(key string) (bool, error)
- func (k KeyValue) Bytes() ([]byte, error)
- func (k KeyValue) Exist(key string) (exists bool)
- func (k KeyValue) Float64Value(key string) (float64, error)
- func (k KeyValue) Interface(i interface{}) error
- func (k KeyValue) Map() map[string]interface{}
- func (k KeyValue) MapString() map[string]string
- func (k KeyValue) NestedListValue(key string) ([]KeyValue, error)
- func (k KeyValue) NestedValue(key string) (KeyValue, error)
- func (k KeyValue) Set(key string, value interface{}) KeyValue
- func (k KeyValue) String() string
- func (k KeyValue) StringValue(key string) (string, error)
- func (k KeyValue) StringsValue(key string) ([]string, error)
- func (k KeyValue) Uint64Value(key string) (uint64, error)
- type List
- func (q *List) Add(key interface{}, value interface{}) error
- func (q *List) Cap() uint
- func (q *List) Exist(key interface{}) bool
- func (q *List) Get(key interface{}) (interface{}, error)
- func (q *List) GetFirst() (interface{}, interface{}, error)
- func (q *List) IsEmpty() bool
- func (q *List) IsFull() bool
- func (q *List) Len() uint
- func (q *List) List() map[interface{}]interface{}
- func (q *List) SetCap(newCap uint) error
- func (q *List) Take(key interface{}) (interface{}, error)
- func (q *List) TakeFirst() (interface{}, interface{}, error)
Constants ¶
const DefaultCap uint = 1_000_000
DefaultCap max amount of data that this list could keep
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type KeyValue ¶
type KeyValue map[string]interface{}
KeyValue is the golang's map with the functions. Important to know that, no value could be `nil`.
func NewFromInterface ¶
NewFromInterface converts the data structure "i" to KeyValue In order to do that, it serializes data structure using json
The data structures should define the json variable names
func NewFromString ¶
NewFromString converts the s string with a json decoder into the kv value
func (KeyValue) BigIntValue ¶
BigIntValue extracts the value as the parsed large number. Use this if the number size is more than 64 bits.
func (KeyValue) Float64Value ¶
Float64Value extracts the float number
func (KeyValue) NestedListValue ¶
NestedListValue returns the parameter as a slice of map:
[]key_value.KeyValue
func (KeyValue) NestedValue ¶
NestedValue returns the parameter as a KeyValue
func (KeyValue) StringValue ¶
StringValue returns the parameter as a string
func (KeyValue) StringsValue ¶
StringsValue returns the list of strings
type List ¶
type List struct {
// contains filtered or unexported fields
}
func NewList ¶
func NewList() *List
NewList returns a new list of the elements that could contain maximum DefaultCap of elements.
The queue has a function that returns the first element by taking it out from the list.
The added elements attached after the last element.
func (*List) Add ¶
Add a new element to the queue. If the element type is not the same as the expected type, then It will silently drop it. Silently drop if the queue is full
func (*List) GetFirst ¶
GetFirst returns the first added element. Returns the kv, value and error if it can not find it.
func (*List) SetCap ¶
SetCap updates the capacity of the list. If the list has more elements than newCap, it throws an error.