add context to store

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2020-09-17 15:15:42 +03:00
parent d59db9df16
commit 8817c110d0
2 changed files with 11 additions and 8 deletions

View File

@ -1,5 +1,7 @@
package store package store
import "context"
type noopStore struct { type noopStore struct {
opts Options opts Options
} }
@ -27,19 +29,19 @@ func (n *noopStore) String() string {
return "noop" return "noop"
} }
func (n *noopStore) Read(key string, opts ...ReadOption) ([]*Record, error) { func (n *noopStore) Read(ctx context.Context, key string, opts ...ReadOption) ([]*Record, error) {
return []*Record{}, nil return []*Record{}, nil
} }
func (n *noopStore) Write(r *Record, opts ...WriteOption) error { func (n *noopStore) Write(ctx context.Context, r *Record, opts ...WriteOption) error {
return nil return nil
} }
func (n *noopStore) Delete(key string, opts ...DeleteOption) error { func (n *noopStore) Delete(ctx context.Context, key string, opts ...DeleteOption) error {
return nil return nil
} }
func (n *noopStore) List(opts ...ListOption) ([]string, error) { func (n *noopStore) List(ctx context.Context, opts ...ListOption) ([]string, error) {
return []string{}, nil return []string{}, nil
} }

View File

@ -3,6 +3,7 @@
package store package store
import ( import (
"context"
"errors" "errors"
"time" "time"
) )
@ -20,13 +21,13 @@ type Store interface {
// Options allows you to view the current options. // Options allows you to view the current options.
Options() Options Options() Options
// Read takes a single key name and optional ReadOptions. It returns matching []*Record or an error. // Read takes a single key name and optional ReadOptions. It returns matching []*Record or an error.
Read(key string, opts ...ReadOption) ([]*Record, error) Read(ctx context.Context, key string, opts ...ReadOption) ([]*Record, error)
// Write() writes a record to the store, and returns an error if the record was not written. // Write() writes a record to the store, and returns an error if the record was not written.
Write(r *Record, opts ...WriteOption) error Write(ctx context.Context, r *Record, opts ...WriteOption) error
// Delete removes the record with the corresponding key from the store. // Delete removes the record with the corresponding key from the store.
Delete(key string, opts ...DeleteOption) error Delete(ctx context.Context, key string, opts ...DeleteOption) error
// List returns any keys that match, or an empty list with no error if none matched. // List returns any keys that match, or an empty list with no error if none matched.
List(opts ...ListOption) ([]string, error) List(ctx context.Context, opts ...ListOption) ([]string, error)
// Close the store // Close the store
Close() error Close() error
// String returns the name of the implementation. // String returns the name of the implementation.