Skip to content
This repository was archived by the owner on Jun 12, 2024. It is now read-only.

Commit 393a39e

Browse files
committed
backend: Context in blob store interface signature
1 parent 15d8d08 commit 393a39e

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

Diff for: backend/internal/core/blobstore/local.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package blobstore
22

33
import (
4+
"context"
45
"io"
56
"os"
67
"path/filepath"
@@ -29,11 +30,11 @@ func NewLocalBlobStore(root string) BlobStore {
2930
}
3031
}
3132

32-
func (l *localBlobStore) Get(key string) (io.ReadCloser, error) {
33+
func (l *localBlobStore) Get(ctx context.Context, key string) (io.ReadCloser, error) {
3334
return os.Open(l.resolvePath(key))
3435
}
3536

36-
func (l *localBlobStore) Put(key string, content io.Reader) (string, error) {
37+
func (l *localBlobStore) Put(ctx context.Context, key string, content io.Reader) (string, error) {
3738
path := pathlib.Safe(l.resolvePath(key))
3839

3940
parent := filepath.Dir(path)
@@ -55,7 +56,7 @@ func (l *localBlobStore) Put(key string, content io.Reader) (string, error) {
5556
return key, nil
5657
}
5758

58-
func (l *localBlobStore) Delete(key string) error {
59+
func (l *localBlobStore) Delete(ctx context.Context, key string) error {
5960
return os.Remove(l.resolvePath(key))
6061
}
6162

Diff for: backend/internal/core/blobstore/store.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package blobstore
33

44
import (
5+
"context"
56
"io"
67
)
78

@@ -12,13 +13,13 @@ import (
1213
type BlobStore interface {
1314
// Get retrieves a blob by key, returning an io.ReadCloser capable of streaming the blob
1415
// contents. Callers should close the returned blob to avoid leaks.
15-
Get(key string) (io.ReadCloser, error)
16+
Get(ctx context.Context, key string) (io.ReadCloser, error)
1617
// Put creates a new blob with the specified key and contents, and returns a normalized key
1718
// that can be used for future R/W.
1819
//
1920
// Note that the returned key may be identical to that supplied in the original request;
2021
// the behavior is implementation-defined.
21-
Put(key string, content io.Reader) (string, error)
22+
Put(ctx context.Context, key string, content io.Reader) (string, error)
2223
// Delete deletes a blob by key.
23-
Delete(key string) error
24+
Delete(ctx context.Context, key string) error
2425
}

Diff for: backend/internal/data/repo/repo_documents.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (r *DocumentRepository) Read(ctx context.Context, id uuid.UUID) (io.ReadClo
6868
return nil, err
6969
}
7070

71-
content, err := r.bs.Get(doc.Path)
71+
content, err := r.bs.Get(ctx, doc.Path)
7272
if err != nil {
7373
return nil, err
7474
}
@@ -84,7 +84,7 @@ func (r *DocumentRepository) Create(ctx context.Context, gid uuid.UUID, doc Docu
8484

8585
key := r.blobKey(gid, ext)
8686

87-
path, err := r.bs.Put(key, doc.Content)
87+
path, err := r.bs.Put(ctx, key, doc.Content)
8888
if err != nil {
8989
return DocumentOut{}, err
9090
}
@@ -109,7 +109,7 @@ func (r *DocumentRepository) Delete(ctx context.Context, id uuid.UUID) error {
109109
return err
110110
}
111111

112-
err = r.bs.Delete(doc.Path)
112+
err = r.bs.Delete(ctx, doc.Path)
113113
if err != nil {
114114
return err
115115
}

0 commit comments

Comments
 (0)