package module
v0.0.0-...-f7115cf Latest Latest

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

Go to latest
Published: Jul 16, 2018 License: MIT Imports: 8 Imported by: 74


Deprecation warning

This repository is no longer maintanied. As the memory backend is useful mostly for unit-tests and proto-typing, the code has been merged into the Git repository, and can be found at import path This repository is kept only for allowing old imports paths to work.

REST Layer Memory backend godoc license build

This REST Layer resource storage backend stores data in memory with no persistence. This package is provided as an implementation example and a test backend to be used for testing only.



Simply create a memory resource handler per resource:

import ""
index.Bind("foo", foo, mem.NewHandler(), resource.DefaultConf)

Latency Simulation

As local memory access is very fast, this handler is not very useful when it comes to working with latency related issues. This handler allows you to simulate latency by setting an artificial delay:

root.Bind("foo", resource.NewResource(foo, mem.NewSlowHandler(5*time.Second), resource.DefaultConf)

With this configuration, the memory handler will pause 5 seconds before processing every request. If the passed net/context is canceled during that wait, the handler won't process the request and return the appropriate rest.Error as specified in the REST Layer storage handler implementation doc.



Package mem is an example REST backend storage that stores everything in memory.



This section is empty.


This section is empty.


This section is empty.


type MemoryHandler

type MemoryHandler struct {
	// If latency is set, the handler will introduce an artificial latency on
	// all operations
	Latency time.Duration
	// contains filtered or unexported fields

MemoryHandler is an example handler storing data in memory

func NewHandler

func NewHandler() *MemoryHandler

NewHandler creates an empty memory handler

func NewSlowHandler

func NewSlowHandler(latency time.Duration) *MemoryHandler

NewSlowHandler creates an empty memory handler with specified latency

func (*MemoryHandler) Clear

func (m *MemoryHandler) Clear(ctx context.Context, q *query.Query) (total int, err error)

Clear clears all items from the memory store matching the lookup

func (*MemoryHandler) Delete

func (m *MemoryHandler) Delete(ctx context.Context, item *resource.Item) (err error)

Delete deletes an item from memory

func (*MemoryHandler) Find

func (m *MemoryHandler) Find(ctx context.Context, q *query.Query) (list *resource.ItemList, err error)

Find items from memory matching the provided lookup

func (*MemoryHandler) Insert

func (m *MemoryHandler) Insert(ctx context.Context, items []*resource.Item) (err error)

Insert inserts new items in memory

func (*MemoryHandler) Update

func (m *MemoryHandler) Update(ctx context.Context, item *resource.Item, original *resource.Item) (err error)

Update replace an item by a new one in memory

Jump to

Keyboard shortcuts

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