https://github.com/rs/rest-layer-mem
REST Layer memory storage handler
https://github.com/rs/rest-layer-mem
Last synced: about 1 year ago
JSON representation
REST Layer memory storage handler
- Host: GitHub
- URL: https://github.com/rs/rest-layer-mem
- Owner: rs
- License: mit
- Created: 2015-08-04T23:02:03.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2018-07-16T07:40:21.000Z (almost 8 years ago)
- Last Synced: 2025-04-15T14:13:10.405Z (about 1 year ago)
- Language: Go
- Size: 9.77 KB
- Stars: 4
- Watchers: 4
- Forks: 5
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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 [](https://godoc.org/github.com/rs/rest-layer-mem) [](https://raw.githubusercontent.com/rs/rest-layer-mem/master/LICENSE) [](https://travis-ci.org/rs/rest-layer-mem)
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:
```go
import "github.com/rs/rest-layer-mem"
```
```go
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:
```go
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](https://github.com/rs/rest-layer#data-storage-handler).