micro/store/store.go

52 lines
945 B
Go
Raw Normal View History

2019-06-12 09:46:20 +03:00
// Package store is an interface for distribute data storage.
package store
2019-05-31 02:43:23 +03:00
import (
"errors"
"time"
)
var (
2019-11-01 17:13:21 +03:00
// ErrNotFound is returned when a Read key doesn't exist
2019-05-31 02:43:23 +03:00
ErrNotFound = errors.New("not found")
2020-01-06 20:44:32 +03:00
// Default store
DefaultStore Store = new(noop)
2019-05-31 02:43:23 +03:00
)
2019-06-12 09:46:20 +03:00
// Store is a data storage interface
type Store interface {
2019-10-24 00:05:39 +03:00
// List all the known records
List() ([]*Record, error)
2019-11-01 17:13:21 +03:00
// Read records with keys
2019-10-24 00:05:39 +03:00
Read(key ...string) ([]*Record, error)
2019-11-01 17:13:21 +03:00
// Write records
2019-10-24 00:05:39 +03:00
Write(rec ...*Record) error
2019-11-01 17:13:21 +03:00
// Delete records with keys
2019-10-24 00:05:39 +03:00
Delete(key ...string) error
2019-05-31 02:43:23 +03:00
}
// Record represents a data record
type Record struct {
2019-06-11 19:49:34 +03:00
Key string
Value []byte
Expiry time.Duration
2019-05-31 02:43:23 +03:00
}
2020-01-06 20:44:32 +03:00
type noop struct{}
func (n *noop) List() ([]*Record, error) {
return nil, nil
}
func (n *noop) Read(key ...string) ([]*Record, error) {
return nil, nil
}
func (n *noop) Write(rec ...*Record) error {
return nil
}
func (n *noop) Delete(key ...string) error {
return nil
}