REST Layer memory storage handler
Go
Switch branches/tags
Nothing to show
Clone or download
smyrman Update README.md
Added deprecation notice.
Latest commit f7115cf Jul 13, 2018
Permalink
Failed to load latest commit information.
.travis.yml Switch to go 1.7 context Dec 8, 2016
LICENSE Migrate from REST Layer main repo Aug 4, 2015
README.md Update README.md Jul 16, 2018
latency.go Switch to go 1.7 context Dec 8, 2016
mem.go
sort.go Migrate from resource.Lookup to query.Query (#5) Aug 1, 2017

README.md

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 https://github.com/rs/rest-layer Git repository, and can be found at import path github.com/rs/rest-layer/resource/testing/mem. 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.

DO NOT USE THIS IN PRODUCTION.

Usage

Simply create a memory resource handler per resource:

import "github.com/rs/rest-layer-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 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.