Skip to content

Commit

Permalink
cmd/go/internal/web: remove a redundant return value
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Bryan C. Mills authored and gopherbot committed Aug 10, 2023
1 parent 8cb5c55 commit 7c2b690
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/cmd/go/internal/web/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 (
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 7c2b690

Please sign in to comment.