Introduction to Go, the tooling and basic language features
Rob Reid @codingconcepts
Nick Lanng @nicklanng
- Install Go
- What is the Go workspace and why is it different to project workspaces
- Data types
- Slices and arrays
- Pointers vs values
- Functions
- FizzBuzz Exercise
- String Calculator Exercise
The easiest way to install go is to use Homebrew.
brew install go
Create a folder for your Go workspace, I like to make a folder at ~/work/go
.
Open your ~/.bashrc or ~/.zshrc (or whatever the config file is for your shell of choice).
You need to set up your environmental variables used for Go tooling and binaries pulled down with go get
.
Add the following lines to your shell config, be sure to set the right path if different:
export GOPATH=$HOME/work/go
export PATH=$PATH:$GOPATH/bin
In this classic coding kata, you are tasked with printing the numbers from 1 to 100.
However, there are some extra rules.
If the number is a multiple of 3 then, instead of the number, print 'Fizz'.
If the number is a multiple of 5 then, instead of the number, print 'Buzz'.
If the number is a multiple of BOTH then instead of the number, print 'FizzBuzz'.
Click here to see the solution!
```go package main
import "fmt"
func main() { for i := 1; i <= 100; i++ { if i%15 == 0 { fmt.Println("FizzBuzz") } else if i%3 == 0 { fmt.Println("Fizz") } else if i%5 == 0 { fmt.Println("Buzz") } else { fmt.Println(i) } } }
</p></details>