store

package
v2.0.12 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2017 License: MIT Imports: 1 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KeyError

type KeyError struct {
	Key string
}

KeyError is returned when a corresponding key is missing in store

func (KeyError) Error

func (ke KeyError) Error() string

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store provides simple thread-safe storage for application. It supposed to be injected into context using WithStore function

func New

func New() *Store

New creates new empty store

func (*Store) Delete

func (s *Store) Delete(key string)

Delete removes value from store

func (*Store) Get

func (s *Store) Get(key string) (interface{}, bool)

Get reads value from the store, returns value and boolean flag

func (*Store) MustGet

func (s *Store) MustGet(key string) interface{}

MustGet reads value from the store and panics if there's no such key

func (*Store) Set

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

Set saves value to the store

func (*Store) Update

func (s *Store) Update(f func(map[string]interface{}) error) error

Update executes a function in read-write atomic transaction. Use this method to modify underlying map in thread-safe way.

func (*Store) View

func (s *Store) View(f func(map[string]interface{}) error) error

View executes a function within read-only atomic transaction. Note that function is granted arbitrary access to the underlying map, and writing operations are possible but thread-unsafe.

Jump to

Keyboard shortcuts

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