Skip to content

Commit

Permalink
fix download fail in the china
Browse files Browse the repository at this point in the history
  • Loading branch information
mei-rune committed Dec 16, 2021
1 parent 5fa3e2c commit d0c3c9b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
44 changes: 35 additions & 9 deletions internal/commands/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,30 @@ var (
installCmdGoHostFlag string
)

func GetGoSourceGitURL() string {
gsURL := os.Getenv("GOUP_GO_SOURCE_GIT_URL")
if gsURL == "" {
gsURL = goSourceGitURL
}
return gsURL
}

func GetGoDownloadBaseURL() string {
gdURL := os.Getenv("GOUP_GO_DOWNLOAD_BASE_URL")
if gdURL == "" {
gdURL = goDownloadBaseURL
}
return gdURL
}

func GetGoHost() string {
gh := os.Getenv("GOUP_GO_HOST")
if gh == "" {
gh = goHost
}
return gh
}

func installCmd() *cobra.Command {
installCmd := &cobra.Command{
Use: "install [VERSION]",
Expand All @@ -54,12 +78,7 @@ number can be provided.`,
RunE: runInstall,
}

gh := os.Getenv("GOUP_GO_HOST")
if gh == "" {
gh = goHost
}

installCmd.PersistentFlags().StringVar(&installCmdGoHostFlag, "host", gh, "host that is used to download Go. The GOUP_GO_HOST environment variable overrides this flag.")
installCmd.PersistentFlags().StringVar(&installCmdGoHostFlag, "host", GetGoHost(), "host that is used to download Go. The GOUP_GO_HOST environment variable overrides this flag.")

return installCmd
}
Expand Down Expand Up @@ -248,10 +267,17 @@ func installTip(clNumber string) error {
if err := os.MkdirAll(root, 0755); err != nil {
return fmt.Errorf("failed to create repository: %v", err)
}
if err := git("clone", "--depth=1", goSourceGitURL, root); err != nil {

if err := git("clone", "--depth=1", GetGoSourceGitURL(), root); err != nil {
return fmt.Errorf("failed to clone git repository: %v", err)
}
if err := git("remote", "add", "upstream", goSourceUpsteamGitURL); err != nil {

gsuURL := os.Getenv("GOUP_GO_SOURCE_GIT_URL")
if gsuURL == "" {
gsuURL = goSourceUpsteamGitURL
}

if err := git("remote", "add", "upstream", gsuURL); err != nil {
return fmt.Errorf("failed to add upstream git repository: %v", err)
}
}
Expand Down Expand Up @@ -618,7 +644,7 @@ func versionArchiveURL(version string) string {
arch = "armv6l"
}

return fmt.Sprintf("%s/%s.%s-%s.%s", goDownloadBaseURL, version, goos, arch, ext)
return fmt.Sprintf("%s/%s.%s-%s.%s", GetGoDownloadBaseURL(), version, goos, arch, ext)
}

// unpackedOkay is a sentinel zero-byte file to indicate that the Go
Expand Down
3 changes: 1 addition & 2 deletions internal/commands/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ func listGoVersions(re string) ([]string, error) {
re = ".+"
} else {
re = fmt.Sprintf(`.*%s.*`, re)

}

cmd := exec.Command("git", "ls-remote", "--sort=version:refname", "--tags", "https://github.com/golang/go")
cmd := exec.Command("git", "ls-remote", "--sort=version:refname", "--tags", GetGoSourceGitURL())
refs, err := cmd.Output()
if err != nil {
return nil, err
Expand Down

0 comments on commit d0c3c9b

Please sign in to comment.