internal/pkg: pass context to file cure
All checks were successful
Test / Create distribution (push) Successful in 47s
Test / Sandbox (push) Successful in 2m52s
Test / ShareFS (push) Successful in 4m42s
Test / Sandbox (race detector) (push) Successful in 5m17s
Test / Hpkg (push) Successful in 5m24s
Test / Hakurei (push) Successful in 5m31s
Test / Hakurei (race detector) (push) Successful in 7m54s
Test / Flake checks (push) Successful in 1m47s
All checks were successful
Test / Create distribution (push) Successful in 47s
Test / Sandbox (push) Successful in 2m52s
Test / ShareFS (push) Successful in 4m42s
Test / Sandbox (race detector) (push) Successful in 5m17s
Test / Hpkg (push) Successful in 5m24s
Test / Hakurei (push) Successful in 5m31s
Test / Hakurei (race detector) (push) Successful in 7m54s
Test / Flake checks (push) Successful in 1m47s
This removes the left over embedded contexts. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -12,8 +12,6 @@ import (
|
||||
// hardcoded as [http.MethodGet]. Request body is not allowed because it cannot
|
||||
// be deterministically represented by Params.
|
||||
type httpArtifact struct {
|
||||
// Caller-supplied context.
|
||||
ctx context.Context
|
||||
// Caller-supplied url string.
|
||||
url string
|
||||
|
||||
@@ -36,18 +34,14 @@ var _ KnownChecksum = new(httpArtifact)
|
||||
// NewHTTPGet returns a new [File] backed by the supplied client. A GET request
|
||||
// is set up for url. If c is nil, [http.DefaultClient] is used instead.
|
||||
func NewHTTPGet(
|
||||
ctx context.Context,
|
||||
c *http.Client,
|
||||
url string,
|
||||
checksum Checksum,
|
||||
) File {
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
if c == nil {
|
||||
c = http.DefaultClient
|
||||
}
|
||||
return &httpArtifact{ctx: ctx, url: url, checksum: checksum, doFunc: c.Do}
|
||||
return &httpArtifact{url: url, checksum: checksum, doFunc: c.Do}
|
||||
}
|
||||
|
||||
// Kind returns the hardcoded [Kind] constant.
|
||||
@@ -73,9 +67,9 @@ func (e ResponseStatusError) Error() string {
|
||||
|
||||
// do sends the caller-supplied request on the caller-supplied [http.Client]
|
||||
// and reads its response body to EOF and returns the resulting bytes.
|
||||
func (a *httpArtifact) do() (data []byte, err error) {
|
||||
func (a *httpArtifact) do(ctx context.Context) (data []byte, err error) {
|
||||
var req *http.Request
|
||||
req, err = http.NewRequestWithContext(a.ctx, http.MethodGet, a.url, nil)
|
||||
req, err = http.NewRequestWithContext(ctx, http.MethodGet, a.url, nil)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -101,7 +95,7 @@ func (a *httpArtifact) do() (data []byte, err error) {
|
||||
|
||||
// Cure completes the http request and returns the resulting response body read
|
||||
// to EOF. Data does not interact with the filesystem.
|
||||
func (a *httpArtifact) Cure() (data []byte, err error) {
|
||||
func (a *httpArtifact) Cure(ctx context.Context) (data []byte, err error) {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
|
||||
@@ -110,7 +104,7 @@ func (a *httpArtifact) Cure() (data []byte, err error) {
|
||||
return a.data, nil
|
||||
}
|
||||
|
||||
if data, err = a.do(); err != nil {
|
||||
if data, err = a.do(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user