You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
804 B
Go
43 lines
804 B
Go
3 years ago
|
package migrate
|
||
|
|
||
|
import (
|
||
|
"net/url"
|
||
|
"os"
|
||
|
"strings"
|
||
|
|
||
|
"github.com/tal-tech/go-zero/core/stringx"
|
||
|
"github.com/tal-tech/go-zero/tools/goctl/rpc/execx"
|
||
|
)
|
||
|
|
||
|
var defaultProxy = "https://goproxy.cn"
|
||
|
var defaultProxies = []string{defaultProxy}
|
||
|
|
||
|
func goProxy() []string {
|
||
|
wd, err := os.Getwd()
|
||
|
if err != nil {
|
||
|
return defaultProxies
|
||
|
}
|
||
|
|
||
|
proxy, err := execx.Run("go env GOPROXY", wd)
|
||
|
if err != nil {
|
||
|
return defaultProxies
|
||
|
}
|
||
|
list := strings.FieldsFunc(proxy, func(r rune) bool {
|
||
|
return r == '|' || r == ','
|
||
|
})
|
||
|
var ret []string
|
||
|
for _, item := range list {
|
||
|
if len(item) == 0 {
|
||
|
continue
|
||
|
}
|
||
|
_, err = url.Parse(item)
|
||
|
if err == nil && !stringx.Contains(ret, item) {
|
||
|
ret = append(ret, item)
|
||
|
}
|
||
|
}
|
||
|
if !stringx.Contains(ret, defaultProxy) {
|
||
|
ret = append(ret, defaultProxy)
|
||
|
}
|
||
|
return ret
|
||
|
}
|