William Petit
8e574c299b
All checks were successful
arcad/edge/pipeline/pr-master This commit looks good
51 lines
946 B
Go
51 lines
946 B
Go
package blob
|
|
|
|
import (
|
|
"context"
|
|
|
|
"forge.cadoles.com/arcad/edge/pkg/storage"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
type OpenBucketArgs struct {
|
|
BucketName string
|
|
}
|
|
|
|
type OpenBucketReply struct {
|
|
BucketID BucketID
|
|
}
|
|
|
|
func (s *Service) OpenBucket(ctx context.Context, args *OpenBucketArgs, reply *OpenBucketReply) error {
|
|
bucket, err := s.store.OpenBucket(ctx, args.BucketName)
|
|
if err != nil {
|
|
return errors.WithStack(err)
|
|
}
|
|
|
|
bucketID, err := NewBucketID()
|
|
if err != nil {
|
|
return errors.WithStack(err)
|
|
}
|
|
|
|
s.buckets.Store(bucketID, bucket)
|
|
|
|
*reply = OpenBucketReply{
|
|
BucketID: bucketID,
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (s *Service) getOpenedBucket(id BucketID) (storage.BlobBucket, error) {
|
|
raw, exists := s.buckets.Load(id)
|
|
if !exists {
|
|
return nil, errors.WithStack(storage.ErrBucketClosed)
|
|
}
|
|
|
|
bucket, ok := raw.(storage.BlobBucket)
|
|
if !ok {
|
|
return nil, errors.Errorf("unexpected type '%T' for blob bucket", raw)
|
|
}
|
|
|
|
return bucket, nil
|
|
}
|