Change the store interface to remove variadic args (#1095)

This commit is contained in:
Asim Aslam
2020-01-08 22:23:14 +00:00
committed by GitHub
parent 78aed5beed
commit a90a74c9e2
13 changed files with 356 additions and 378 deletions

View File

@@ -20,11 +20,11 @@ type Store interface {
// List all the known records
List() ([]*Record, error)
// Read records with keys
Read(key ...string) ([]*Record, error)
Read(key string, opts ...ReadOption) ([]*Record, error)
// Write records
Write(rec ...*Record) error
Write(*Record) error
// Delete records with keys
Delete(key ...string) error
Delete(key string) error
}
// Record represents a data record
@@ -34,6 +34,13 @@ type Record struct {
Expiry time.Duration
}
type ReadOptions struct {
// Read key as a prefix
Prefix bool
}
type ReadOption func(o *ReadOptions)
type noop struct{}
func (n *noop) Init(...Option) error {
@@ -44,14 +51,14 @@ func (n *noop) List() ([]*Record, error) {
return nil, nil
}
func (n *noop) Read(key ...string) ([]*Record, error) {
func (n *noop) Read(key string, opts ...ReadOption) ([]*Record, error) {
return nil, nil
}
func (n *noop) Write(rec ...*Record) error {
func (n *noop) Write(rec *Record) error {
return nil
}
func (n *noop) Delete(key ...string) error {
func (n *noop) Delete(key string) error {
return nil
}