store: add blob interface with file implementation (#2004)

This commit is contained in:
ben-toogood
2020-09-15 14:05:10 +01:00
committed by GitHub
parent 3bb76868d1
commit d5bfa1e795
3 changed files with 253 additions and 0 deletions

34
store/blob.go Normal file
View File

@@ -0,0 +1,34 @@
package store
import (
"errors"
"io"
)
var (
// ErrMissingKey is returned when no key is passed to blob store Read / Write
ErrMissingKey = errors.New("Missing key")
)
// BlobStore is an interface for reading / writing blobs
type BlobStore interface {
Read(key string, opts ...BlobOption) (io.Reader, error)
Write(key string, blob io.Reader, opts ...BlobOption) error
Delete(key string, opts ...BlobOption) error
}
// BlobOptions contains options to use when interacting with the store
type BlobOptions struct {
// Namespace to from
Namespace string
}
// BlobOption sets one or more BlobOptions
type BlobOption func(o *BlobOptions)
// BlobNamespace sets the Namespace option
func BlobNamespace(ns string) BlobOption {
return func(o *BlobOptions) {
o.Namespace = ns
}
}