mem
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
README¶
REST Layer Memory backend


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.
DO NOT USE THIS IN PRODUCTION.
Usage
Simply create a memory resource handler per resource:
import "github.com/rs/rest-layer/resource/testing/mem"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 passednet/context is canceled during that wait, the handler won't process the request and return the appropriaterest.Error as specified in the REST Layerstorage handler implementation doc.
Documentation¶
Overview¶
Package mem is an example REST backend storage that stores everything in memory.
Index¶
- type MemoryHandler
- func (m *MemoryHandler) Clear(ctx context.Context, q *query.Query) (total int, err error)
- func (m *MemoryHandler) Delete(ctx context.Context, item *resource.Item) (err error)
- func (m *MemoryHandler) Find(ctx context.Context, q *query.Query) (list *resource.ItemList, err error)
- func (m *MemoryHandler) Insert(ctx context.Context, items []*resource.Item) (err error)
- func (m *MemoryHandler) Update(ctx context.Context, item *resource.Item, original *resource.Item) (err error)
Constants¶
This section is empty.
Variables¶
This section is empty.
Functions¶
This section is empty.
Types¶
typeMemoryHandler¶
type MemoryHandler struct {sync.RWMutex// If Latency is set, the handler will introduce an artificial latency on// all operations.Latencytime.Duration// contains filtered or unexported fields}MemoryHandler is an example handler storing data in memory.
funcNewSlowHandler¶
func NewSlowHandler(latencytime.Duration) *MemoryHandler
NewSlowHandler creates an empty memory handler with specified latency.
func (*MemoryHandler)Find¶
func (m *MemoryHandler) Find(ctxcontext.Context, q *query.Query) (list *resource.ItemList, errerror)
Find items from memory matching the q.