memstore

package
v0.0.0-...-20f3002 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2017 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package memstore contains a store which is just a collection of key-value entries with immutability capabilities.

Created after that proposal: https://github.com/iris-contrib/community-board/issues/5 and it's being used by session entries (session lifetime) and context's entries (per-request).

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

This section is empty.

Types

type Entry

type Entry struct {
	Key string
	// contains filtered or unexported fields
}

Entry is the entry of the context storage Store - .Values()

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 (*Store) Get

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

Get returns the entry's value based on its key.

func (*Store) GetInt

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

GetInt returns the entry's value as int, based on its key.

func (*Store) GetInt64

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

GetInt64 returns the entry's value as int64, based on its key.

func (*Store) GetString

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

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

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) Set

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

Set saves a value to the key-value storage. See `SetImmutable` and `Get`.

func (*Store) SetImmutable

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

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.

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