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

Commit

Permalink
backend: Context in blob store interface signature
Browse files Browse the repository at this point in the history
  • Loading branch information
LINKIWI committed Feb 4, 2024
1 parent 15d8d08 commit 393a39e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
7 changes: 4 additions & 3 deletions backend/internal/core/blobstore/local.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package blobstore

import (
"context"
"io"
"os"
"path/filepath"
Expand Down Expand Up @@ -29,11 +30,11 @@ func NewLocalBlobStore(root string) BlobStore {
}
}

func (l *localBlobStore) Get(key string) (io.ReadCloser, error) {
func (l *localBlobStore) Get(ctx context.Context, key string) (io.ReadCloser, error) {
return os.Open(l.resolvePath(key))
}

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

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

func (l *localBlobStore) Delete(key string) error {
func (l *localBlobStore) Delete(ctx context.Context, key string) error {
return os.Remove(l.resolvePath(key))
}

Expand Down
7 changes: 4 additions & 3 deletions backend/internal/core/blobstore/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package blobstore

import (
"context"
"io"
)

Expand All @@ -12,13 +13,13 @@ import (
type BlobStore interface {
// Get retrieves a blob by key, returning an io.ReadCloser capable of streaming the blob
// contents. Callers should close the returned blob to avoid leaks.
Get(key string) (io.ReadCloser, error)
Get(ctx context.Context, key string) (io.ReadCloser, error)
// Put creates a new blob with the specified key and contents, and returns a normalized key
// that can be used for future R/W.
//
// Note that the returned key may be identical to that supplied in the original request;
// the behavior is implementation-defined.
Put(key string, content io.Reader) (string, error)
Put(ctx context.Context, key string, content io.Reader) (string, error)
// Delete deletes a blob by key.
Delete(key string) error
Delete(ctx context.Context, key string) error
}
6 changes: 3 additions & 3 deletions backend/internal/data/repo/repo_documents.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (r *DocumentRepository) Read(ctx context.Context, id uuid.UUID) (io.ReadClo
return nil, err
}

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

key := r.blobKey(gid, ext)

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

err = r.bs.Delete(doc.Path)
err = r.bs.Delete(ctx, doc.Path)
if err != nil {
return err
}
Expand Down

0 comments on commit 393a39e

Please sign in to comment.