Documentation ¶
Overview ¶
Package memstore contains a store which is just a collection of key-value entries with immutability capabilities.
Developers can use that storage to their own apps if they like its behavior. It's fast and in the same time you get read-only access (safety) when you need it.
Index ¶
- Variables
- func GobEncode(store Store, w io.Writer) error
- func GobEncodeEntry(entry Entry, w io.Writer) error
- func GobSerialize(store Store) ([]byte, error)
- func GobSerializeEntry(entry Entry) ([]byte, error)
- type Entry
- type Store
- func (r *Store) Get(key string) interface{}
- func (r *Store) GetInt(key string) (int, error)
- func (r *Store) GetInt64(key string) (int64, error)
- func (r *Store) GetString(key string) string
- func (r *Store) Len() int
- func (r *Store) Remove(key string) bool
- func (r *Store) Reset()
- func (r *Store) Save(key string, value interface{}, immutable bool) (Entry, bool)
- func (r Store) Serialize() []byte
- func (r *Store) Set(key string, value interface{}) (Entry, bool)
- func (r *Store) SetImmutable(key string, value interface{}) (Entry, bool)
- func (r *Store) Visit(visitor func(key string, value interface{}))
Constants ¶
This section is empty.
Variables ¶
var ErrIntParse = errors.New("unable to find or parse the integer, found: %#v")
ErrIntParse returns an error message when int parse failed it's not statical error, it depends on the failed value.
Functions ¶
func GobEncodeEntry ¶
GobEncodeEntry accepts an entry and writes as series of bytes to the "w" writer.
func GobSerialize ¶
GobSerialize same as GobEncode but it returns the bytes using a temp buffer.
func GobSerializeEntry ¶
GobSerializeEntry same as GobEncodeEntry but it returns the bytes using a temp buffer.
Types ¶
type Entry ¶
type Entry struct { Key string ValueRaw interface{} // contains filtered or unexported fields }
Entry is the entry of the context storage Store - .Values()
func GobDecodeEntry ¶
GobDecodeEntry accepts a series of bytes and returns the entry.
type Store ¶
type Store []Entry
Store is a collection of key-value entries with immutability capabilities.
func (*Store) Remove ¶
Remove deletes an entry linked to that "key", returns true if an entry is actually removed.
func (*Store) Save ¶
Save same as `Set` However, if "immutable" is true then saves it as immutable (same as `SetImmutable`).
Returns the entry and true if it was just inserted, meaning that it will return the entry and a false boolean if the entry exists and it has been updated.
func (*Store) Set ¶
Set saves a value to the key-value storage. Returns the entry and true if it was just inserted, meaning that it will return the entry and a false boolean if the entry exists and it has been updated.
See `SetImmutable` and `Get`.
func (*Store) SetImmutable ¶
SetImmutable saves a value to the key-value storage. Unlike `Set`, the output value cannot be changed by the caller later on (when .Get OR .Set)
An Immutable entry should be only changed with a `SetImmutable`, simple `Set` will not work if the entry was immutable, for your own safety.
Returns the entry and true if it was just inserted, meaning that it will return the entry and a false boolean if the entry exists and it has been updated.
Use it consistently, it's far slower than `Set`. Read more about muttable and immutable go types: https://stackoverflow.com/a/8021081