This section includes exercises and small projects which illustrate the basics of Go programming language. Things such as: types, data structures, functions, pointers, packages and others.
- Go Learning Resources
- Go Program Anatomy
- Number Systems
- Basic Types
- Constants
- Packages
- Vendor directory
- Custom import paths
- Custom package manager
- Package Management
- Go modules
- Go module proxy
- Internal directory
Before trying any of these examples make sure to have the Go
binary installed on your platform.
OSX:
# Install Homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# Install Go
brew install go
Linux:
# Move into $HOME directory
cd ~
# Download the binary for your distribution
curl -O https://dl.google.com/go/go1.12.linux-amd64.tar.gz
# Verify that the downloaded binary is not corrupted. Check if the hash matches the one from downloads page
sha256sum go1.12.linux-amd64.tar.gz
# Extract the binary
tar xvf go1.12.linux-amd64.tar.gz
# Make root user the owner of Go workspace
sudo chown -R root:root ./go
# Move go directory to a standard location
sudo mv go /usr/local
For more details regarding Go
installation check out
For downloading Go
binary for your platform checkout
To check if you installed Go
successfully type:
# Displays installed Go version
go version
# Displays all environment variables defined by Go
go env
Docker:
docker run -it golang:1.11
sudo nano ~/.profile
# Linux
export GOPATH=/usr/local/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:/$GOBIN
# OSX
export GOPATH=$HOME/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:/$GOBIN
# Save File
# Restart shell configuration
source ~/.profile
You can also install other Go
tools which will help you have a more productive development process
go get -u golang.org/x/tools/...
go get -u golang.org/x/lint/golint
go get -u golang.org/x/tools/cmd/goimports
-
Format your entire code recursively using
go fmt ./...
-
Lint your entire code recursively using
golint ./...
Happy hacking gophers 🚀🚀🚀