Skip to content

Commit b04f386

Browse files
committed
goproxy-forward-util-succuss-or-last
1 parent 65ef999 commit b04f386

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

src/cmd/go/internal/modfetch/proxy.go

+18-12
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ control systems. Setting GOPROXY to "off" disallows downloading modules from
4040
any source. Otherwise, GOPROXY is expected to be a comma-separated list of
4141
the URLs of module proxies, in which case the go command will fetch modules
4242
from those proxies. For each request, the go command tries each proxy in sequence,
43-
only moving to the next if the current proxy returns a 404 or 410 HTTP response.
43+
only moving to the next if the current proxy failed.
4444
The string "direct" may appear in the proxy list, to cause a direct connection to
4545
be attempted at that point in the search.
4646
@@ -415,7 +415,7 @@ func (r *lazyRepo) Zip(dst io.Writer, version string) error {
415415
// The list must be non-empty and all Repos
416416
// must return the same result from ModulePath.
417417
// For each method, the repos are tried in order
418-
// until one succeeds or returns a non-ErrNotExist (non-404) error.
418+
// until one succeeds.
419419
type listRepo []Repo
420420

421421
func (l listRepo) ModulePath() string {
@@ -425,49 +425,55 @@ func (l listRepo) ModulePath() string {
425425
func (l listRepo) Versions(prefix string) ([]string, error) {
426426
for i, r := range l {
427427
v, err := r.Versions(prefix)
428-
if i == len(l)-1 || !errors.Is(err, os.ErrNotExist) {
429-
return v, err
428+
if err != nil && i != len(l) - 1{
429+
continue
430430
}
431+
return v, err
431432
}
432433
panic("no repos")
433434
}
434435

435436
func (l listRepo) Stat(rev string) (*RevInfo, error) {
436437
for i, r := range l {
437438
info, err := r.Stat(rev)
438-
if i == len(l)-1 || !errors.Is(err, os.ErrNotExist) {
439-
return info, err
439+
if err != nil && i != len(l) - 1{
440+
continue
440441
}
442+
return info, err
441443
}
442444
panic("no repos")
443445
}
444446

445447
func (l listRepo) Latest() (*RevInfo, error) {
446448
for i, r := range l {
447449
info, err := r.Latest()
448-
if i == len(l)-1 || !errors.Is(err, os.ErrNotExist) {
449-
return info, err
450+
if err != nil && i != len(l) - 1{
451+
continue
450452
}
453+
return info, err
451454
}
452455
panic("no repos")
453456
}
454457

455458
func (l listRepo) GoMod(version string) ([]byte, error) {
456459
for i, r := range l {
457460
data, err := r.GoMod(version)
458-
if i == len(l)-1 || !errors.Is(err, os.ErrNotExist) {
459-
return data, err
461+
if err != nil && i != len(l) - 1{
462+
continue
460463
}
464+
return data, err
461465
}
462466
panic("no repos")
463467
}
464468

465469
func (l listRepo) Zip(dst io.Writer, version string) error {
466470
for i, r := range l {
467471
err := r.Zip(dst, version)
468-
if i == len(l)-1 || !errors.Is(err, os.ErrNotExist) {
469-
return err
472+
if err != nil && i != len(l) - 1{
473+
continue
470474
}
475+
return err
471476
}
472477
panic("no repos")
473478
}
479+

0 commit comments

Comments
 (0)