memstore

package
v8.5.2+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2017 License: BSD-3-Clause Imports: 8 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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 GobEncode

func GobEncode(store Store, w io.Writer) error

GobEncode accepts a store and writes as series of bytes to the "w" writer.

func GobEncodeEntry

func GobEncodeEntry(entry Entry, w io.Writer) error

GobEncodeEntry accepts an entry and writes as series of bytes to the "w" writer.

func GobSerialize

func GobSerialize(store Store) ([]byte, error)

GobSerialize same as GobEncode but it returns the bytes using a temp buffer.

func GobSerializeEntry

func GobSerializeEntry(entry Entry) ([]byte, error)

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

func GobDecodeEntry(b []byte) (entry Entry, err error)

GobDecodeEntry accepts a series of bytes and returns the entry.

func (Entry) Value

func (e Entry) Value() interface{}

Value returns the value of the entry, respects the immutable.

type Store

type Store []Entry

Store is a collection of key-value entries with immutability capabilities.

func GobDecode

func GobDecode(b []byte) (store Store, err error)

GobDecode accepts a series of bytes and returns the store.

func (*Store) Get

func (r *Store) Get(key string) interface{}

Get returns the entry's value based on its key. If not found returns nil.

func (*Store) GetBool

func (r *Store) GetBool(key string) (bool, error)

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

func (r *Store) GetBoolDefault(key string, def bool) (bool, error)

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

func (r *Store) GetDefault(key string, def interface{}) interface{}

GetDefault returns the entry's value based on its key. If not found returns "def".

func (*Store) GetFloat64

func (r *Store) GetFloat64(key string) (float64, error)

GetFloat64 returns the entry's value as float64, based on its key. If not found returns 0.0.

func (*Store) GetFloat64Default

func (r *Store) GetFloat64Default(key string, def float64) (float64, error)

GetFloat64Default returns the entry's value as float64, based on its key. If not found returns "def".

func (*Store) GetInt

func (r *Store) GetInt(key string) (int, error)

GetInt returns the entry's value as int, based on its key. If not found returns 0.

func (*Store) GetInt64

func (r *Store) GetInt64(key string) (int64, error)

GetInt64 returns the entry's value as int64, based on its key. If not found returns 0.0.

func (*Store) GetInt64Default

func (r *Store) GetInt64Default(key string, def int64) (int64, error)

GetInt64Default returns the entry's value as int64, based on its key. If not found returns "def".

func (*Store) GetIntDefault

func (r *Store) GetIntDefault(key string, def int) (int, error)

GetIntDefault returns the entry's value as int, based on its key. If not found returns "def".

func (*Store) GetString

func (r *Store) GetString(key string) string

GetString returns the entry's value as string, based on its key.

func (*Store) GetStringDefault

func (r *Store) GetStringDefault(key string, def string) string

GetStringDefault returns the entry's value as string, based on its key. If not found returns "def".

func (*Store) GetStringTrim

func (r *Store) GetStringTrim(name string) string

GetStringTrim returns the entry's string value without trailing spaces.

func (*Store) Len

func (r *Store) Len() int

Len returns the full length of the entries.

func (*Store) Remove

func (r *Store) Remove(key string) bool

Remove deletes an entry linked to that "key", returns true if an entry is actually removed.

func (*Store) Reset

func (r *Store) Reset()

Reset clears all the request entries.

func (*Store) Save

func (r *Store) Save(key string, value interface{}, immutable bool) (Entry, bool)

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

func (r Store) Serialize() []byte

Serialize returns the byte representation of the current Store.

func (*Store) Set

func (r *Store) Set(key string, value interface{}) (Entry, bool)

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

func (r *Store) SetImmutable(key string, value interface{}) (Entry, bool)

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

func (*Store) Visit

func (r *Store) Visit(visitor func(key string, value interface{}))

Visit accepts a visitor which will be filled by the key-value objects.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL