forked from TrueCloudLab/restic
all: Drop ctxhttp
This package is no longer needed, since we can use the stdlib's http.NewRequestWithContext. backend/rclone already did, but it needed a different error check due to a difference between net/http and ctxhttp. Also, store the http.Client by value in the REST backend (changed to a pointer when ctxhttp was introduced) and use errors.WithStack instead of errors.Wrap where the message was no longer accurate. Errors from http.NewRequestWithContext will start with "net/http" or "net/url", so they're easy to identify.
This commit is contained in:
parent
1a6160d152
commit
d4aadfa389
3 changed files with 27 additions and 32 deletions
|
@ -10,7 +10,6 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/net/context/ctxhttp"
|
||||
)
|
||||
|
||||
// Release collects data about a single release on GitHub.
|
||||
|
@ -53,7 +52,7 @@ func GitHubLatestRelease(ctx context.Context, owner, repo string) (Release, erro
|
|||
defer cancel()
|
||||
|
||||
url := fmt.Sprintf("https://api.github.com/repos/%s/%s/releases/latest", owner, repo)
|
||||
req, err := http.NewRequest(http.MethodGet, url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
||||
if err != nil {
|
||||
return Release{}, err
|
||||
}
|
||||
|
@ -61,7 +60,7 @@ func GitHubLatestRelease(ctx context.Context, owner, repo string) (Release, erro
|
|||
// pin API version 3
|
||||
req.Header.Set("Accept", "application/vnd.github.v3+json")
|
||||
|
||||
res, err := ctxhttp.Do(ctx, http.DefaultClient, req)
|
||||
res, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return Release{}, err
|
||||
}
|
||||
|
@ -112,7 +111,7 @@ func GitHubLatestRelease(ctx context.Context, owner, repo string) (Release, erro
|
|||
}
|
||||
|
||||
func getGithubData(ctx context.Context, url string) ([]byte, error) {
|
||||
req, err := http.NewRequest(http.MethodGet, url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -120,7 +119,7 @@ func getGithubData(ctx context.Context, url string) ([]byte, error) {
|
|||
// request binary data
|
||||
req.Header.Set("Accept", "application/octet-stream")
|
||||
|
||||
res, err := ctxhttp.Do(ctx, http.DefaultClient, req)
|
||||
res, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue