Installing on Linux

sudo add-apt-repository ppa:gophers/archive -y
sudo apt-get update
sudo apt-get install golang-1.10-go -y

Installing golang/dep (Package Manager)

brew install dep

# Linux
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh

Install all dependencies recursively

To install all dependencies of a golang project or golang projects recursively with the go get command, change directory into the project and simply run:

go get ./...

Cross-platform compilation

# For example you can do this from OSX machine
GOOS=linux GOARCH=amd64 go build

possible GOOS value:

  • darwin
  • linux
  • windows

possible GOARCH value:

  • 386
  • amd64

Manipulating Slice

  1. https://github.com/golang/go/wiki/SliceTricks
  2. https://stackoverflow.com/questions/25025409/delete-element-in-a-slice

Manipulating JSON


Rewriting Request Body

We need to modify the content length if we modify http request body.

req.ContentLength = int64(len(b))
req.Body = ioutil.NopCloser(bytes.NewReader(b))

See this.


Do this inside one of your project

dep ensure -add github.com/golang/mock/gomock
go get github.com/golang/mock/mockgen
# Ensure your $GOPATH/bin is in your $PATH
mkdir mock
mockgen -destination=mock/mock_<file_name>.go -package=mock <package> <interface>

Limit of HTTP Handler Concurrent Connection


Useful Standard Library


Useful Libraries

  1. CLI App Framework

Best Practices