mirror of
https://github.com/kevin-DL/m3o-go.git
synced 2026-01-20 14:05:07 +00:00
M3O SDK Concept
This commit is contained in:
48
store/file/file.go
Normal file
48
store/file/file.go
Normal 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
|
||||
}
|
||||
50
store/keyvalue/keyvalue.go
Normal file
50
store/keyvalue/keyvalue.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user