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.
18 type step func(context.Context) error
20 func welcome(ctx context.Context) error {
21 fmt.Println("Welcome to the Go installer!")
22 answer, err := prompt(ctx, "Would you like to install Go? Y/n", "Y")
26 if strings.ToLower(answer) != "y" {
27 fmt.Println("Exiting install.")
34 func checkOthers(ctx context.Context) error {
35 // TODO: if go is currently installed install new version over that
36 path, err := whichGo(ctx)
38 fmt.Printf("Cannot check if Go is already installed:\n%v\n", err)
43 if path != installPath {
44 fmt.Printf("Go is already installed at %v; remove it from your PATH.\n", path)
49 func chooseVersion(ctx context.Context) error {
55 *goVersion, err = getLatestGoVersion()
60 answer, err := prompt(ctx, fmt.Sprintf("The latest Go version is %s, install that? Y/n", *goVersion), "Y")
65 if strings.ToLower(answer) != "y" {
66 // TODO: handle passing a version
67 fmt.Println("Aborting install.")
74 func downloadGo(ctx context.Context) error {
75 answer, err := prompt(ctx, fmt.Sprintf("Download Go version %s to %s? Y/n", *goVersion, installPath), "Y")
80 if strings.ToLower(answer) != "y" {
81 fmt.Println("Aborting install.")
85 fmt.Printf("Downloading Go version %s to %s\n", *goVersion, installPath)
86 fmt.Println("This may take a bit of time...")
88 if err := downloadGoVersion(*goVersion, runtime.GOOS, arch, installPath); err != nil {
92 if err := appendToPATH(filepath.Join(installPath, "bin")); err != nil {
96 fmt.Println("Downloaded!")
100 func setupGOPATH(ctx context.Context) error {
101 answer, err := prompt(ctx, "Would you like us to setup your GOPATH? Y/n", "Y")
106 if strings.ToLower(answer) != "y" {
107 fmt.Println("Exiting and not setting up GOPATH.")
108 return errExitCleanly
111 fmt.Println("Setting up GOPATH")
112 home, err := getHomeDir()
117 gopath := os.Getenv("GOPATH")
120 gopath = filepath.Join(home, "go")
121 if err := persistEnvVar("GOPATH", gopath); err != nil {
124 fmt.Println("GOPATH has been set up!")
126 verbosef("GOPATH is already set to %s", gopath)
129 if err := appendToPATH(filepath.Join(gopath, "bin")); err != nil {
132 return persistEnvChangesForSession()