William Petit
8e574c299b
All checks were successful
arcad/edge/pipeline/pr-master This commit looks good
61 lines
1001 B
Go
61 lines
1001 B
Go
package blob
|
|
|
|
import (
|
|
"fmt"
|
|
"sync"
|
|
|
|
"forge.cadoles.com/arcad/edge/pkg/storage"
|
|
"github.com/google/uuid"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
type BucketID string
|
|
type WriterID string
|
|
type ReaderID string
|
|
|
|
type Service struct {
|
|
store storage.BlobStore
|
|
buckets sync.Map
|
|
writers sync.Map
|
|
readers sync.Map
|
|
}
|
|
|
|
func NewService(store storage.BlobStore) *Service {
|
|
return &Service{
|
|
store: store,
|
|
}
|
|
}
|
|
|
|
func NewBucketID() (BucketID, error) {
|
|
uuid, err := uuid.NewUUID()
|
|
if err != nil {
|
|
return "", errors.WithStack(err)
|
|
}
|
|
|
|
id := BucketID(fmt.Sprintf("bucket-%s", uuid.String()))
|
|
|
|
return id, nil
|
|
}
|
|
|
|
func NewWriterID() (WriterID, error) {
|
|
uuid, err := uuid.NewUUID()
|
|
if err != nil {
|
|
return "", errors.WithStack(err)
|
|
}
|
|
|
|
id := WriterID(fmt.Sprintf("writer-%s", uuid.String()))
|
|
|
|
return id, nil
|
|
}
|
|
|
|
func NewReaderID() (ReaderID, error) {
|
|
uuid, err := uuid.NewUUID()
|
|
if err != nil {
|
|
return "", errors.WithStack(err)
|
|
}
|
|
|
|
id := ReaderID(fmt.Sprintf("reader-%s", uuid.String()))
|
|
|
|
return id, nil
|
|
}
|