feat: Add migrate (#1419)

* Add migrate

* Remove unused module

* refactor filename

* rename refactor to migrate

Co-authored-by: anqiansong <anqiansong@bytedance.com>
This commit is contained in:
anqiansong
2022-01-06 18:48:34 +08:00
committed by GitHub
parent 892f93a716
commit 9d67fc4cfb
7 changed files with 317 additions and 3 deletions

View File

@@ -0,0 +1,42 @@
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
}