Movatterモバイル変換


[0]ホーム

URL:


mem

package
v0.2.0Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2019 License:MITImports:8Imported by:8

Details

Repository

github.com/rs/rest-layer

Links

README

REST Layer Memory backendgodoclicensebuild

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

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.

funcNewHandler

func NewHandler() *MemoryHandler

NewHandler creates an empty memory handler.

funcNewSlowHandler

func NewSlowHandler(latencytime.Duration) *MemoryHandler

NewSlowHandler creates an empty memory handler with specified latency.

func (*MemoryHandler)Clear

func (m *MemoryHandler) Clear(ctxcontext.Context, q *query.Query) (totalint, errerror)

Clear clears all items from the memory store matching q.

func (*MemoryHandler)Delete

func (m *MemoryHandler) Delete(ctxcontext.Context, item *resource.Item) (errerror)

Delete deletes an item from memory.

func (*MemoryHandler)Find

func (m *MemoryHandler) Find(ctxcontext.Context, q *query.Query) (list *resource.ItemList, errerror)

Find items from memory matching the q.

func (*MemoryHandler)Insert

func (m *MemoryHandler) Insert(ctxcontext.Context, items []*resource.Item) (errerror)

Insert inserts new items in memory.

func (*MemoryHandler)Update

func (m *MemoryHandler) Update(ctxcontext.Context, item *resource.Item, original *resource.Item) (errerror)

Update replace an item by a new one in memory.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp