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
- func (e Entry) BoolDefault(def bool) (bool, error)
- func (e Entry) Float64Default(def float64) (float64, error)
- func (e Entry) GetByKindOrNil(k reflect.Kind) interface{}
- func (e Entry) Int64Default(def int64) (int64, error)
- func (e Entry) IntDefault(def int) (int, error)
- func (e Entry) String() string
- func (e Entry) StringDefault(def string) string
- func (e Entry) StringTrim() string
- func (e Entry) Value() interface{}
- type Store
- func (r *Store) Get(key string) interface{}
- func (r *Store) GetBool(key string) (bool, error)
- func (r *Store) GetBoolDefault(key string, def bool) (bool, error)
- func (r *Store) GetDefault(key string, def interface{}) interface{}
- func (r *Store) GetEntry(key string) *Entry
- func (r *Store) GetFloat64(key string) (float64, error)
- func (r *Store) GetFloat64Default(key string, def float64) (float64, error)
- func (r *Store) GetInt(key string) (int, error)
- func (r *Store) GetInt64(key string) (int64, error)
- func (r *Store) GetInt64Default(key string, def int64) (int64, error)
- func (r *Store) GetIntDefault(key string, def int) (int, error)
- func (r *Store) GetString(key string) string
- func (r *Store) GetStringDefault(key string, def string) string
- func (r *Store) GetStringTrim(name 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 ¶
ErrIntParse returns an error message when int parse failed it's not statical error, it depends on the failed value.
Functions ¶
func GobEncode ¶
GobEncode accepts a store and writes as series of bytes to the "w" writer.
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.
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.
func (Entry) BoolDefault ¶ added in v8.5.9
BoolDefault returns the user's value as bool. a string which is "1" or "t" or "T" or "TRUE" or "true" or "True" or "0" or "f" or "F" or "FALSE" or "false" or "False". Any other value returns an error.
If not found returns "def".
func (Entry) Float64Default ¶ added in v8.5.9
Float64Default returns the entry's value as float64. If not found returns "def".
func (Entry) GetByKindOrNil ¶ added in v8.5.9
GetByKindOrNil will try to get this entry's value of "k" kind, if value is not that kind it will NOT try to convert it the "k", instead it will return nil, except if boolean; then it will return false even if the value was not bool.
If the "k" kind is not a string or int or int64 or bool then it will return the raw value of the entry as it's.
func (Entry) Int64Default ¶ added in v8.5.9
Int64Default returns the entry's value as int64. If not found returns "def".
func (Entry) IntDefault ¶ added in v8.5.9
IntDefault returns the entry's value as int. If not found returns "def".
func (Entry) String ¶ added in v8.5.9
String returns the entry's value as string.
func (Entry) StringDefault ¶ added in v8.5.9
StringDefault returns the entry's value as string. If not found returns "def".
func (Entry) StringTrim ¶ added in v8.5.9
StringTrim returns the entry's string value without trailing spaces.
type Store ¶
type Store []Entry
Store is a collection of key-value entries with immutability capabilities.
func GobDecode ¶
GobDecode accepts a series of bytes and returns the store.
func (*Store) Get ¶
Get returns the entry's value based on its key. If not found returns nil.
func (*Store) GetBool ¶ added in v8.4.2
GetBool returns the user's value as bool, based on its key. a string which is "1" or "t" or "T" or "TRUE" or "true" or "True" or "0" or "f" or "F" or "FALSE" or "false" or "False". Any other value returns an error.
If not found returns false.
func (*Store) GetBoolDefault ¶ added in v8.4.4
GetBoolDefault returns the user's value as bool, based on its key. a string which is "1" or "t" or "T" or "TRUE" or "true" or "True" or "0" or "f" or "F" or "FALSE" or "false" or "False". Any other value returns an error.
If not found returns "def".
func (*Store) GetDefault ¶ added in v8.4.3
GetDefault returns the entry's value based on its key. If not found returns "def". This function checks for immutability as well, the rest don't.
func (*Store) GetEntry ¶ added in v8.5.9
GetEntry returns a pointer to the "Entry" found with the given "key" if nothing found then it returns nil, so be careful with that, it's not supposed to be used by end-developers.
func (*Store) GetFloat64 ¶ added in v8.4.3
GetFloat64 returns the entry's value as float64, based on its key. If not found returns 0.0.
func (*Store) GetFloat64Default ¶ added in v8.4.3
GetFloat64Default returns the entry's value as float64, based on its key. If not found returns "def".
func (*Store) GetInt ¶
GetInt returns the entry's value as int, based on its key. If not found returns 0.
func (*Store) GetInt64 ¶
GetInt64 returns the entry's value as int64, based on its key. If not found returns 0.0.
func (*Store) GetInt64Default ¶ added in v8.4.3
GetInt64Default returns the entry's value as int64, based on its key. If not found returns "def".
func (*Store) GetIntDefault ¶ added in v8.4.3
GetIntDefault returns the entry's value as int, based on its key. If not found returns "def".
func (*Store) GetString ¶
GetString returns the entry's value as string, based on its key.
func (*Store) GetStringDefault ¶ added in v8.4.3
GetStringDefault returns the entry's value as string, based on its key. If not found returns "def".
func (*Store) GetStringTrim ¶ added in v8.4.3
GetStringTrim returns the entry's string value without trailing spaces.
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) Serialize ¶
Serialize returns the byte representation of the current Store.
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