Go Language
We use Go (Golang) in a variety of services in OPG Digital and it is typically our first choice for new development due to its efficiency and strong type safety.
We do not have any preferred frameworks for Go applications: instead we mostly rely on the standard library wherever possible to reduce our dependency graph and keep code simple and consistent.
Example OPG Go repositories
We have many services built with Go, but here are a few repositories that provide a good range of examples of our usage.
- opg-sirius-supervision-finance-hub is a full-stack service built with Go to process payments and allow Supervision Billing to manage accounts for clients
- opg-modernising-lpa is the new Make and Register service built entirely in Go
- opg-data-lpa-store is a API for storing and accessing Digital LPAs built with Go-based Lambdas
Standard tools
We often use these libraries in our Go applications:
- golangci-lint - Go linter that bundles multiple other linting tools
- testify - Unit testing toolkit providing mock and assertion functions
- mockery - Generates mocks for testing
- air - CLI package that automatically rebuilds and reloads Go apps with local changes
- delve - Debugger for Go applications
- validator - Struct and field validation for Go applications
- sqlc - Generates type-safe Go code from SQL queries
- goose - Database migration tool for Go applications
UI
Our Go applications typically use Go templates for rendering HTML, with small JS scripts for interactivity. For conditional rendering of the DOM, we have had success with HTMX (see finance-hub for examples).
Learning Resources
These are resources we’ve found useful in OPG for learning and mastering Go.
- https://tour.golang.org/ - The official Golang tour for learning Go. Very informative
- https://gobyexample.com - Introductory site that explains with clear examples.
- https://github.com/tmrts/go-patterns - A whole GitHub repo full of READMEs on different design patterns you can use when building out a application
- https://lets-go.alexedwards.net/#packages - Build a Go web application. Alex Edwards is a very well known Go engineer who’s written a very informative book on building a whole web application in Go. (Might have to ask line manager about getting the money to buy the book) His main blog also has some very good free resources on different topics in Go
- https://github.com/golang/go/wiki/CodeReviewComments - Resources you can use when reviewing a PR to try and make sure the Go code is following Go’s best practices.
- https://medium.com/wesionary-team/pointers-and-passby-value-reference-in-golang-a00c8c59b7f1 - understanding Pointers and Values
- https://github.com/dariubs/GoBooks - GitHub repo with a list of a bunch of books which you may find useful
Video Courses
Ask your line manager about a Pluralsight license.
- https://www.pluralsight.com/courses/creating-web-applications-go-update - Creating Web Applications with Go, quick and simple intro course focusing on web applications.
- https://app.pluralsight.com/library/courses/go-create-test-applications - Testing Go Applications, look at golang test tools, including its benchmarking library
- https://app.pluralsight.com/library/courses/go-delve-debugging-applications - A look at using the golang debugger with your code