@@ -10,6 +10,7 @@ import (
1010 "os/exec"
1111 "path/filepath"
1212 "strings"
13+ "time"
1314
1415 "github.com/Masterminds/semver"
1516 "github.com/murphysecurity/murphysec/infra/logctx"
@@ -21,34 +22,36 @@ import (
2122
2223func checkNetworkEnvironment (ctx context.Context ) bool {
2324 var goProxy []string
24-
2525 if strings .Contains (os .Getenv ("GOPROXY" ), "," ) {
2626 goProxy = strings .Split (os .Getenv ("GOPROXY" ), "," )
2727 } else {
2828 goProxy = append (goProxy , os .Getenv ("GOPROXY" ))
2929 }
30- networkEnvironment := false
30+ timeout := 10 * time .Second
31+ client := http.Client {
32+ Timeout : timeout , // 使用设置的超时时间
33+ }
3134 for range 3 {
3235 for _ , j := range goProxy {
3336 if j == "direct" {
3437 continue
3538 }
36- r , e := http .Get (j )
39+ r , e := client .Get (j )
40+ if e != nil {
41+ logctx .Use (ctx ).Warn ("test network environment http get error :" + e .Error ())
42+ continue
43+ }
3744 if r != nil && r .StatusCode == http .StatusRequestTimeout {
3845 logctx .Use (ctx ).Warn ("test network environment http get timeout :" + j )
3946 r .Body .Close ()
4047 continue
4148 }
42- if e != nil {
43- logctx .Use (ctx ).Warn ("test network environment http get error :" + e .Error ())
44- continue
45- }
4649 logctx .Use (ctx ).Debug ("test network environment http get success :" + j )
47- networkEnvironment = true
48- break
50+ r . Body . Close ()
51+ return true
4952 }
5053 }
51- return networkEnvironment
54+ return false
5255}
5356func goModTidy (ctx context.Context , path string ) error {
5457 logger := logctx .Use (ctx )
0 commit comments