1
0
mirror of https://github.com/golang/go synced 2024-11-23 07:40:04 -07:00

cmd/go/internal/web: remove a redundant return value

The URL return value from the fetch helper in web.get was always
either the passed in URL (on success) or nil (on failure).
Remove it to reduce code complexity.

For #61877.

Change-Id: I0ce4602b921d1c996aa988e7d3f83996511ccd72
Reviewed-on: https://go-review.googlesource.com/c/go/+/518016
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
This commit is contained in:
Bryan C. Mills 2023-08-09 17:22:20 -04:00 committed by Gopher Robot
parent 8cb5c55118
commit 7c2b69080a

View File

@ -173,7 +173,7 @@ func get(security SecurityMode, url *urlpkg.URL) (*Response, error) {
}
}
fetch := func(url *urlpkg.URL) (*urlpkg.URL, *http.Response, error) {
fetch := func(url *urlpkg.URL) (*http.Response, error) {
// Note: The -v build flag does not mean "print logging information",
// despite its historical misuse for this in GOPATH-based go get.
// We print extra logging in -x mode instead, which traces what
@ -184,7 +184,7 @@ func get(security SecurityMode, url *urlpkg.URL) (*Response, error) {
req, err := http.NewRequest("GET", url.String(), nil)
if err != nil {
return nil, nil, err
return nil, err
}
if url.Scheme == "https" {
auth.AddCredentials(req)
@ -197,7 +197,7 @@ func get(security SecurityMode, url *urlpkg.URL) (*Response, error) {
release, err := base.AcquireNet()
if err != nil {
return nil, nil, err
return nil, err
}
var res *http.Response
@ -218,7 +218,7 @@ func get(security SecurityMode, url *urlpkg.URL) (*Response, error) {
// CheckRedirect fails, and even then the returned Response.Body is
// already closed.”
release()
return nil, nil, err
return nil, err
}
// “If the returned error is nil, the Response will contain a non-nil Body
@ -228,7 +228,7 @@ func get(security SecurityMode, url *urlpkg.URL) (*Response, error) {
ReadCloser: body,
afterClose: release,
}
return url, res, err
return res, err
}
var (
@ -241,8 +241,10 @@ func get(security SecurityMode, url *urlpkg.URL) (*Response, error) {
*secure = *url
secure.Scheme = "https"
fetched, res, err = fetch(secure)
if err != nil {
res, err = fetch(secure)
if err == nil {
fetched = secure
} else {
if cfg.BuildX {
fmt.Fprintf(os.Stderr, "# get %s: %v\n", secure.Redacted(), err)
}
@ -284,8 +286,10 @@ func get(security SecurityMode, url *urlpkg.URL) (*Response, error) {
return nil, fmt.Errorf("refusing to pass credentials to insecure URL: %s", insecure.Redacted())
}
fetched, res, err = fetch(insecure)
if err != nil {
res, err = fetch(insecure)
if err == nil {
fetched = insecure
} else {
if cfg.BuildX {
fmt.Fprintf(os.Stderr, "# get %s: %v\n", insecure.Redacted(), err)
}