M3O SDK Concept

This commit is contained in:
Ben Toogood
2020-11-25 16:06:44 +00:00
parent 7818a050c2
commit 5fa6c1244f
21 changed files with 1293 additions and 524 deletions

48
store/file/file.go Normal file
View File

@@ -0,0 +1,48 @@
// Package file provides a file store
package file
import (
"io"
"time"
)
// NewClient returns an RPC client for the file store. It will communicate with the M3O file
// service.
func NewClient() File {
}
// NewMock returns an in-memory mock for the file store. It is designed for use in tests.
func NewMock() File {
}
// File is an interface providing file storage
type File interface {
Read(key string) (Result, error)
List(ListOptions) ([]Result, error)
Write(key string, value io.Reader, opts WriteOptions) error
Delete(key string) error
}
// ListOptions are used to filter results of the list operation
type ListOptions struct {
// Prefix limits the results to those where the key has the given prefix
Prefix string
}
// WriteOptions are provided when writing a file to the store
type WriteOptions struct {
// Expiry sets the time at which the file should be deleted
Expiry time.Time
// Encoding of the file, e.g. PDF
Encoding string
}
// Result returned from the key value store
type Result struct {
Key string
Value io.Reader
Expiry time.Time
Encoding string
}

View File

@@ -0,0 +1,50 @@
// Package keyvalue provides a key value store
package keyvalue
import (
"errors"
"time"
)
var (
// ErrRecordNotFound is returned when trying to read a record which does not exist
ErrRecordNotFound = errors.New("Record not found")
)
// NewClient returns an RPC client for the KeyValue store. It will communicate with the M3O KeyValue
// service.
func NewClient() Store {
}
// NewMock returns an in-memory mock for the KeyValue store. It is designed for use in tests.
func NewMock() Store {
}
// Store is an interface providing key value storage
type Store interface {
Read(key string) (Record, error)
List(ListOptions) ([]Record, error)
Write(key, value string, opts WriteOptions) error
Delete(key string) error
}
// ListOptions are used to filter results of the list operation
type ListOptions struct {
// Prefix limits the results to those where the key has the given prefix
Prefix string
}
// WriteOptions are provided when writing a file to the store
type WriteOptions struct {
// Expiry sets the time at which the file should be deleted
Expiry time.Time
}
// Record returned from the key value store
type Record struct {
Key string
Value string
Expiry time.Time
}