fix(server): Thread request context to all relevant places

Previously background contexts where created where necessary (e.g. in
GCS interactions). Should I begin to use request timeouts or other
context-dependent things in the future, it's useful to have the actual
HTTP request context around.

This threads the request context through the application to all places
that need it.
This commit is contained in:
Vincent Ambo 2019-10-28 18:32:02 +01:00 committed by Vincent Ambo
parent 30e618b65b
commit d8fba23365
6 changed files with 20 additions and 23 deletions

View file

@ -2,6 +2,7 @@
package storage
import (
"context"
"fmt"
"io"
"net/http"
@ -34,7 +35,7 @@ func (b *FSBackend) Name() string {
return fmt.Sprintf("Filesystem (%s)", b.path)
}
func (b *FSBackend) Persist(key string, f func(io.Writer) (string, int64, error)) (string, int64, error) {
func (b *FSBackend) Persist(ctx context.Context, key string, f Persister) (string, int64, error) {
full := path.Join(b.path, key)
dir := path.Dir(full)
err := os.MkdirAll(dir, 0755)
@ -53,12 +54,12 @@ func (b *FSBackend) Persist(key string, f func(io.Writer) (string, int64, error)
return f(file)
}
func (b *FSBackend) Fetch(key string) (io.ReadCloser, error) {
func (b *FSBackend) Fetch(ctx context.Context, key string) (io.ReadCloser, error) {
full := path.Join(b.path, key)
return os.Open(full)
}
func (b *FSBackend) Move(old, new string) error {
func (b *FSBackend) Move(ctx context.Context, old, new string) error {
newpath := path.Join(b.path, new)
err := os.MkdirAll(path.Dir(newpath), 0755)
if err != nil {