1 // Copyright 2017 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
19 type step func(context.Context) error
21 func welcome(ctx context.Context) error {
22 fmt.Println("Welcome to the Go installer!")
23 answer, err := prompt(ctx, "Would you like to install Go? Y/n", "Y")
27 if strings.ToLower(answer) != "y" {
28 fmt.Println("Exiting install.")
35 func checkOthers(ctx context.Context) error {
36 // TODO: if go is currently installed install new version over that
37 path, err := whichGo(ctx)
39 fmt.Printf("Cannot check if Go is already installed:\n%v\n", err)
44 if path != installPath {
45 fmt.Printf("Go is already installed at %v; remove it from your PATH.\n", path)
50 func chooseVersion(ctx context.Context) error {
56 *goVersion, err = getLatestGoVersion()
61 answer, err := prompt(ctx, fmt.Sprintf("The latest Go version is %s, install that? Y/n", *goVersion), "Y")
66 if strings.ToLower(answer) != "y" {
67 // TODO: handle passing a version
68 fmt.Println("Aborting install.")
75 func downloadGo(ctx context.Context) error {
76 answer, err := prompt(ctx, fmt.Sprintf("Download Go version %s to %s? Y/n", *goVersion, installPath), "Y")
81 if strings.ToLower(answer) != "y" {
82 fmt.Println("Aborting install.")
86 fmt.Printf("Downloading Go version %s to %s\n", *goVersion, installPath)
87 fmt.Println("This may take a bit of time...")
89 if err := downloadGoVersion(*goVersion, runtime.GOOS, arch, installPath); err != nil {
93 if err := appendToPATH(filepath.Join(installPath, "bin")); err != nil {
97 fmt.Println("Downloaded!")
101 func setupGOPATH(ctx context.Context) error {
102 answer, err := prompt(ctx, "Would you like us to setup your GOPATH? Y/n", "Y")
107 if strings.ToLower(answer) != "y" {
108 fmt.Println("Exiting and not setting up GOPATH.")
109 return errExitCleanly
112 fmt.Println("Setting up GOPATH")
113 home, err := getHomeDir()
118 gopath := os.Getenv("GOPATH")
121 gopath = filepath.Join(home, "go")
122 if err := persistEnvVar("GOPATH", gopath); err != nil {
125 fmt.Println("GOPATH has been set up!")
127 verbosef("GOPATH is already set to %s", gopath)
130 if err := appendToPATH(filepath.Join(gopath, "bin")); err != nil {
133 return persistEnvChangesForSession()