diff --git a/cache.go b/cache.go index 000f353..0a7feaf 100644 --- a/cache.go +++ b/cache.go @@ -11,10 +11,12 @@ import ( "github.com/pkg/errors" ) +const lastSuccessStatus = 299 + func renewCache(ctx context.Context, url string) (*meta, error) { cachePath := urlToCachePath(url) - req, err := http.NewRequest(http.MethodGet, url, nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) if err != nil { return nil, errors.Wrap(err, "Unable to create request") } @@ -29,7 +31,7 @@ func renewCache(ctx context.Context, url string) (*meta, error) { } defer resp.Body.Close() - if resp.StatusCode > 299 { + if resp.StatusCode > lastSuccessStatus { return nil, errors.Errorf("HTTP status signaled failure: %d", resp.StatusCode) } diff --git a/storage_local.go b/storage_local.go index dd61766..55c8406 100644 --- a/storage_local.go +++ b/storage_local.go @@ -12,6 +12,8 @@ import ( "github.com/pkg/errors" ) +const storageLocalDirPermission = 0o700 + type storageLocal struct { basePath string } @@ -47,7 +49,7 @@ func (s storageLocal) LoadMeta(ctx context.Context, cachePath string) (*meta, er func (s storageLocal) StoreFile(ctx context.Context, cachePath string, metadata *meta, data io.Reader) (err error) { cachePath = path.Join(s.basePath, cachePath) - if err = os.MkdirAll(path.Dir(cachePath), 0700); err != nil { + if err = os.MkdirAll(path.Dir(cachePath), storageLocalDirPermission); err != nil { return errors.Wrap(err, "create cache dir") }