-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add install instructions and small mad lib program
- Loading branch information
Showing
2 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
You can download the Go tools package installer or the archive from: https://golang.org/dl/ | ||
|
||
If you download the archive: | ||
|
||
Extract into /usr/local | ||
|
||
Add Go PATH to your system profile: | ||
|
||
export PATH=$PATH:/usr/local/go/bin | ||
|
||
If you want to install the Go tools into a different location you can set a GOROOT env variable to point to that directory | ||
|
||
Add GOROOT to your .bash_profile or .profile: | ||
|
||
export GOROOT=$HOME/go | ||
export PATH=$PATH:$GOROOT/bin | ||
|
||
If you download the package installer: | ||
|
||
Open the installer and install the tools. | ||
|
||
Mac OS X: | ||
|
||
The installer will install go to /usr/local/go and will put the directory (/usr/local/go/bin) into your PATH env variable. | ||
|
||
Test that you've installed Go correctly and run your first "Hello, Word." program: | ||
|
||
Create a new directory and set up a workspace: | ||
|
||
Set a GOPATH env variable in your .bash_profile or .profile: | ||
|
||
$ export GOPATH=$HOME/workspace | ||
|
||
Create your first Go program: | ||
|
||
Make the directories src/github.com/(your github username)/hello inside your workspace directory. | ||
While inside the hello directory create a file named hello.go and add: | ||
|
||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
fmt.Printf("hello, world\n") | ||
} | ||
|
||
Compile your first Go program: | ||
|
||
$ go install github.com/(your github username)/hello | ||
|
||
Run your first Go program: | ||
|
||
After compiling the program an executable will be inside the bin directory of the workspace: | ||
$HOME/workspace/github.com/(your github username)/bin or $GOPATH/bin | ||
|
||
To run the program run: | ||
|
||
$ $GOPATH/bin/hello | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
fmt.Println("Mad lib program!") | ||
fmt.Println("Give me a noun!: ") | ||
var noun string | ||
var verb string | ||
var adjective string | ||
var noun2 string | ||
fmt.Scanln(&noun) | ||
fmt.Println("Give me a verb!: ") | ||
fmt.Scanln(&verb) | ||
fmt.Println("Give me an adjective!: ") | ||
fmt.Scanln(&adjective) | ||
fmt.Println("Give me another noun!: ") | ||
fmt.Scanln(&noun2) | ||
|
||
fmt.Println(fmt.Sprintf("The %v %v to the %v %v", noun, verb, adjective, noun2)) | ||
} |