edge/pkg/storage/blob_store.go

67 lines
1.3 KiB
Go

package storage
import (
"context"
"errors"
"io"
"time"
"github.com/oklog/ulid/v2"
)
var (
ErrBucketClosed = errors.New("bucket closed")
ErrBlobNotFound = errors.New("blob not found")
)
type BlobID string
func NewBlobID() BlobID {
return BlobID(ulid.Make().String())
}
type BlobStore interface {
OpenBucket(ctx context.Context, name string) (BlobBucket, error)
ListBuckets(ctx context.Context) ([]string, error)
DeleteBucket(ctx context.Context, name string) error
}
type BlobBucket interface {
Name() string
Close() error
Get(ctx context.Context, id BlobID) (BlobInfo, error)
Delete(ctx context.Context, id BlobID) error
NewReader(ctx context.Context, id BlobID) (io.ReadSeekCloser, error)
NewWriter(ctx context.Context, id BlobID) (io.WriteCloser, error)
List(ctx context.Context) ([]BlobInfo, error)
Size(ctx context.Context) (int64, error)
}
type BlobInfo interface {
ID() BlobID
Bucket() string
ModTime() time.Time
Size() int64
ContentType() string
}
type BucketListOptions struct {
Limit *int
Offset *int
}
type BucketListOptionsFunc func(o *BucketListOptions)
func WithBucketListLimit(limit int) BucketListOptionsFunc {
return func(o *BucketListOptions) {
o.Limit = &limit
}
}
func WithBucketListOffset(offset int) BucketListOptionsFunc {
return func(o *BucketListOptions) {
o.Offset = &offset
}
}