Golang is a programming language with focus on pragmatism, keeping things simple, wisdom instead of cleverness, and engineering in the large.
Go is great choice for CLI tools, API servers, code that is getting deployed into external environments (e.g. agents), and other network services, be it extremely small (micro-services) or large (in terms of code or team size).
Beginners
- start with A tour of Go
- The Go Blog describes lots of best practices
- in case you need it, solutions to the Go tour
Advanced
- use Effective Go as a reference later
- GoDoc for information on Go packages
- Security Guidelines
- Go at Google: Language Design in the Service of Software Engineering: overview of the philosophy behind Go
- Building web applications with Golang ebook
- use
goimports
to automatically manage import statements and format the code for you - follow the idiomatic code style of Go's standard library, the naming conventions, the documented best practices in the Go Blog, and the code review comments
- vendor dependencies using glide, at least until the official package manager is stable
- Only vendor dependencies for binaries, not for libraries (learn more)
- Use pure functions if possible
- provide dependencies explicitly, as small and tightly-scoped interfaces
- make the zero value useful
- always provide timeouts for HTTP requests
- goimports: configure your editor to run this after each file save
- gorename: performs precise type-safe renaming of identifiers in Go source code
- gofix
- gometalinter: runs dozens of linters in parallel over your source code, normalizing their output
These libraries are considered the best ones for their intended purpose and should be used unless there are justifiable reasons to do otherwise. Trying a more modern alternative with clear benefits is a good reason here. This is a living list, please suggest better ones via a PR.
Larger frameworks
- build CLI apps: Cobra
- simple Sinatra or Flask like server: github.com/gin-gonic/gin
Testing
Debugging
- go tooling in action (video): explains how to compile, test, profile, and optimize Go code using flame graphs
Smaller libraries
- Postgres: github.com/lib/pq
- logging: github.com/Sirupsen/logrus
- generate UUIDs: github.com/satori/go.uuid
- parse CLI flags: github.com/jessevdk/go-flags
- rate limiting: golang.org/x/time/rate
- HTTP middleware: github.com/urfave/negroni
Find more in the awesome Go list
- Vim: vim-go
- Emacs: go-mode
- Sublime: go-sublime
- Jetbrains: Gogland
- Visual Studio Code with the Go plugin
- use Bash for simple scripts that don't need to run on Windows
- consider Electron if your application needs a GUI, especially when you want to reuse an existing web UI