If you are upgrading from an older version of Go you must first remove the existing version. To remove an existing Go installation from your system delete the go directory.
# Linux & Mac
$ sudo rm -rf /usr/local/go
# Windows
Delete c:\Go
To install Go, run the following command:
$ go_version=1.24.1
$ cd ~/Downloads
$ sudo apt-get update
$ sudo apt-get install -y build-essential git curl wget
$ wget https://go.dev/dl/go${go_version}.linux-amd64.tar.gz
$ sudo tar -C /usr/local -xzf go${go_version}.linux-amd64.tar.gz
$ sudo chown -R $(id -u):$(id -g) /usr/local/go
$ rm go${go_version}.linux-amd64.tar.gz
Add go to your $PATH variable
$ mkdir $HOME/go
$ nano ~/.bashrc
export GOPATH=$HOME/go
export PATH=$GOPATH/bin:/usr/local/go/bin:$PATH
$ source ~/.bashrc
$ go version
cannot allocate memory
: http://stackoverflow.com/a/35027241
Read these books / articles / web pages in order:
- https://github.com/golang/go/wiki/Switch
- Slices
- 10 things you did not know
- 50 Shades of Go: Traps, Gotchas, and Common Mistakes for New Golang Devs
- Effective GO
If you just want a quick refresh of the syntax, the following link is very handy: A Tour of Go
$ export GO111MODULE=on
- https://github.com/luciotato/golang-notes/blob/master/OOP.md
- http://www.hydrogen18.com/blog/golang-embedding.html
- http://www.goinggo.net/2014/05/methods-interfaces-and-embedded-types.html
- Basic Concepts
- Video: Concurrency Made Easy (Practical Tips For Effective Concurrency In Go)
- Video: Kavya Joshi - Understanding Channels
- Channel Axioms
- Curious Channels
- Why are there nil channels in Go?
- The Behavior Of Channels
- https://blog.golang.org/pipelines
-
Use
go fmt <file>.go
-
Install golint
$ go get -u github.com/golang/lint/golint
$ golint <file>.go
- go vet examines Go source code and reports suspicious constructs. See how to use it here.
- Command goimports updates your Go import lines, adding missing ones and removing unreferenced ones.
https://godoc.org/golang.org/x/tools/cmd/goimports
- HTTP: The Protocol Every Web Developer Must Know - Part 1
- HTTP: The Protocol Every Web Developer Must Know - Part 2
- HTTP Status Codes in 60 Seconds
- A Beginner’s Guide to HTTP and REST
- HTTP Headers for Dummies
- Creating A Simple Web Server With Golang
- Encoding and Decoding JSON, with Go’s net/http package
- https://github.com/go-chi/chi
- https://golang.org/pkg/net/http/
- https://cryptic.io/go-http/
- https://github.com/google/go-querystring
- https://github.com/tent/http-link-go
- Golang httptrace Example
- How to re-use HTTP Connections in Go
- https://github.com/hashicorp/go-cleanhttp
// By default, Transport caches connections for future re-use.
// This may leave many open connections when accessing many hosts.
// This behavior can be managed using Transport's CloseIdleConnections method
// and the MaxIdleConnsPerHost and DisableKeepAlives fields.
//
// Transports should be reused instead of created as needed.
// Transports are safe for concurrent use by multiple goroutines.
- http://json.org/
- http://blog.golang.org/json-and-go
- https://gobyexample.com/json
- http://mholt.github.io/json-to-go/
- How to Parse a JSON Request Body in Go
- JSON and struct composition in Go
- Custom Marshaller/Unmarshaller
- https://medium.com/@IndianGuru/understanding-go-s-template-package-c5307758fab0
- https://hackernoon.com/golang-template-2-template-composition-and-how-to-organize-template-files-4cb40bcdf8f6
- https://golang.org/pkg/text/template/
- https://gist.github.com/tamalsaha/cc86951e3ef7ae23de34f2b116814541
- http://gohugo.io/templates/go-templates/
- http://golang.org/pkg/html/template/
- http://macaron.gogs.io/docs/middlewares/templating.html
- https://player.oreilly.com/videos/9781491938294
https://github.com/jmespath/go-jmespath
https://github.com/davecgh/go-spew
https://github.com/jmhodges/clock
Where you'd use time.Now, instead use clk.Now where clk is an instance of Clock. When running your code in production, pass it a Clock given by Default() and when you're running it in your tests, pass it an instance of Clock from NewFake().
Clock Utility Methods: https://github.com/jinzhu/now
- https://github.com/stretchr/testify
- https://golang.org/pkg/testing/
- https://blog.alexellis.io/golang-writing-unit-tests/
- https://blog.codeship.com/testing-in-go/
- https://speakerdeck.com/mitchellh/advanced-testing-with-go
Mocks
HTTP Testing
- http://www.markjberger.com/testing-web-apps-in-golang/
- http://keighl.com/post/mocking-http-responses-in-golang/
- https://blog.pivotal.io/labs/labs/a-rubyist-leaning-go-testing-http-handlers
BDD Testing
HTTP Load testing tool
- An Introduction to "go tool trace"
- https://golang.org/pkg/net/http/pprof/
- Creating call graph in golang
- https://github.com/uber/go-torch
It will show how pprof can be used to analyze both CPU and heap profile as well as demonstrate how to use go-torch to build Flamegraphs. This process makes it easier to identify hotspots in your service and gives you a better understanding of where time is spent.