Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: remap package names #26911

Closed
wpecker opened this issue Aug 10, 2018 · 1 comment
Closed

cmd/go: remap package names #26911

wpecker opened this issue Aug 10, 2018 · 1 comment

Comments

@wpecker
Copy link

wpecker commented Aug 10, 2018

Can vgo support features similar to the following? In order to solve the network problem in China?
If the code is downloaded from a similar source to golang.org, we can configure the corresponding github to pull the code.

The following configuration is what I did for glide, it is very convenient to use, perfect compatibility, and is a network proxy problem for China.

[[kogwf]]
   package = 'gopkg.in/'
	repo    = 'github.com/'
	rule    = true

[[kogwf]]
	package = 'go.googlesource.com/'
	repo    = 'github.com/golang/'

[[kogwf]]
	package = 'golang.org/x/'
	repo    = 'github.com/golang/'

[[kogwf]]
	package = 'google.golang.org/grpc'
   repo    = 'github.com/grpc/grpc-go'

[[kogwf]]
   package = 'google.golang.org/genproto'
   repo    = 'github.com/google/go-genproto'    

[[kogwf_mto]]
   old_url     = 'rsc.io/'
   old_paths   = ['letsencrypt','rsc']
   new_url     = 'github.com/spiderorg/'

[[kogwf_mto]]
   old_url     = 'github.com/'
   old_paths   = ['sirupsen/logrus','Sirupsen/logrus','Masterminds/vcs','penhauer-xiao/cnsimhash','dgryski/go-simstore','wangbin/jiebago','orcaman/concurrent-map', 'go-playground/pool','carlescere/scheduler','penhauer-xiao/al-uuid','penhauer-xiao/gpool']
   new_url     = 'github.com/spiderorg/'

[[kogwf_otom]]
   old_url     = 'google.golang.org/'
   new_url     = 'github.com/golang/'
   new_paths   = ['appengine','protobuf', 'perf', 'oauth2', 'mock', 'glog', 'groupcache']
   
[[kogwf_otom]]
   old_url     = 'google.golang.org/'
   new_url     = 'github.com/google/'
   new_paths   = [
'skia-buildbot', 'trillian', 'gapid', 'go-cmp', 'fscrypt', 'blueprint', 'pprof' ,
'mtail', 'cloudprober',
'zoekt', 'keytransparency', 'syzkaller', 'grumpy',
'go-github', 'certificate-transparency-go', 'periph', 'okay',
'google-api-go-client','jsonapi','uuid','vmregistry',
'badwolf', 'martian', 'tcpproxy', 'lvmd', 'credstore',
'metaserver', 'microdhcpd', 'pubkeystore', 'cloud-print-connector',
'gopacket', 'git-appraise', 'stenographer', 'gousb',
'safebrowsing', 'cadvisor']

My glide code like as below

/*
gopkg.in/user/pkg.v3                 → github.com/user/pkg                 (branch/tag v3, v3.N, or v3.N.M)
gopkg.in/user/pkg.v3/sub_pkg         → github.com/user/pkg/sub_pkg         (branch/tag v3, v3.N, or v3.N.M)
gopkg.in/user/pkg.v3/sub_pkg/sub_pkg → github.com/user/pkg/sub_pkg/sub_pkg (branch/tag v3, v3.N, or v3.N.M)
*/
func gopkg_in_user(remote string) (newRepository, branch string) {
	if s := strings.Split(remote, separated_path); len(s) >= 3 {
		pkgVer := splitPkgVer(s[2])
		newRepository = fmt.Sprintf("https://%s/%s/%s", s[0], s[1], pkgVer[0])
		logrus.Warnln("github.com/user/pkg Mode:", remote, newRepository, pkgVer[1])
		return newRepository, pkgVer[1]
	}
	return "", ""
}

/*
gopkg.in/pkg.v3                 → github.com/go-pkg/pkg                  (branch/tag v3, v3.N, or v3.N.M)
gopkg.in/pkg.v3/sub_pkg         → github.com/go-pkg/pkg/sub_pkg          (branch/tag v3, v3.N, or v3.N.M)
gopkg.in/pkg.v3/sub_pkg/sub_pkg → github.com/go-pkg/pkg/sub_pkg/sub_pkg  (branch/tag v3, v3.N, or v3.N.M)
*/
func gopkg_in(url string, maps map[string]interface{}) (newRepository, branch string) {
	Package, ok1 := maps["package"]
	repo, ok2 := maps["repo"]
	rule, ok3 := maps["rule"]

	if !ok1 || !ok2 || !ok3 {
		return "", ""
	}

	if !rule.(bool) {
		return "", ""
	}

	if !strings.Contains(url, Package.(string)) {
		return "", ""
	}

	remote := strings.Replace(url, Package.(string), repo.(string), -1)
	var s []string
	if s = strings.Split(remote, separated_path); len(s) < 2 {
		return "", ""
	}

	pkgVer := splitPkgVer(s[1])
	if len(pkgVer) != 0 {
		newRepository = fmt.Sprintf("https://%s/go-%s/%s", s[0], pkgVer[0], pkgVer[0])
		logrus.Warnln("github.com/go-pkg/pkg Mode:", url, newRepository, pkgVer[1])
		return newRepository, pkgVer[1]
	}

	return gopkg_in_user(remote)
}

func other_in(url string, maps map[string]interface{}) (newRepository, branch string) {
	rawUrl, ok1 := maps["package"]
	newUrl, ok2 := maps["repo"]
	if !ok1 || !ok2 {
		return "", ""
	}

	if !strings.Contains(url, rawUrl.(string)) {
		return "", ""
	}

	newRepository = strings.Replace(url, rawUrl.(string), newUrl.(string), -1)
	s := strings.Split(newRepository, separated_path)
	if len(s) < 3 {
		return "", ""
	}

	t := separated_path + s[2]
	baseUrl := strings.Split(newRepository, t)[0]
	newRepository = fmt.Sprintf("https://%s/%s", baseUrl, s[2])

	logrus.Warnln("KGWF Mode:", url, newRepository)
	return newRepository, ""
}
@ianlancetaylor ianlancetaylor changed the title Can vgo support features similar to the following? In order to solve the network problem ? cmd/go: remap package names Aug 10, 2018
@ianlancetaylor
Copy link
Contributor

See go help goproxy.

@golang golang locked and limited conversation to collaborators Aug 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants