diff options
author | Vincent Ambo <tazjin@google.com> | 2019-10-28T17·32+0100 |
---|---|---|
committer | Vincent Ambo <github@tazj.in> | 2019-10-28T21·31+0100 |
commit | d8fba233655e127d54926394eacd4b9391ec8b8b (patch) | |
tree | c005b0c965864de6b30ef683c9057d01494d2192 /tools/nixery/server/storage/filesystem.go | |
parent | 30e618b65bdd330ea5904b2be00cbac46d5b03e3 (diff) |
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.
Diffstat (limited to 'tools/nixery/server/storage/filesystem.go')
-rw-r--r-- | tools/nixery/server/storage/filesystem.go | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/tools/nixery/server/storage/filesystem.go b/tools/nixery/server/storage/filesystem.go index 8aca20aac2d0..3fb91bc5e134 100644 --- a/tools/nixery/server/storage/filesystem.go +++ b/tools/nixery/server/storage/filesystem.go @@ -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 { |