Where to go after this course
You now know the core of Go: values and control flow, functions, slices and maps, structs and interfaces, generics, errors, JSON, goroutines and channels. That is enough to read most Go code and to write real programs. This lesson points you to good next steps.
Write tests
Go has testing built in. Put tests in a file whose name ends in _test.go, next to the code. Each test is a function whose name starts with Test and that takes a *testing.T:
package main
import "testing"
func TestDeliveryFee(t *testing.T) {
got := deliveryFee(6)
if got != 12 {
t.Errorf("deliveryFee(6) = %d, want 12", got)
}
}
The command go test finds and runs every test in the package and reports which ones failed. Run your tests after every change. They tell you at once when a change breaks something that used to work. This is the first habit to build.
Build a web service
Go is used a lot for servers, and the standard library already has a web server in the net/http package. A complete server fits in a few lines:
package main
import (
"fmt"
"net/http"
)
func hello(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Hello from Go")
}
func main() {
http.HandleFunc("/", hello)
http.ListenAndServe(":8080", nil)
}
Run it on your own computer and open http://localhost:8080 in a browser. The server uses goroutines to serve many users at the same time, so the concurrency you learned is used right away. Next, learn the context package, which lets a request stop its work when the user goes away or a time limit passes. Then combine net/http with encoding/json to build a small JSON API.
Learn the tools
These commands come with Go, and almost every Go project uses them:
| Command | What it does |
|---|---|
gofmt | formats your code in the standard Go style |
go vet | finds code that compiles but is probably wrong |
go test -race | runs tests and reports data races, like the one in the Mutex lesson |
go mod tidy | keeps go.mod matching your imports |
Read the standard library
Before you add a package from someone else, check the standard library. It has packages for files (os, bufio), time, text, sorting, JSON, HTTP and much more. The documentation for every package is at pkg.go.dev.
Newer features
This course runs Go 1.22. Go 1.23 added iterators: you can write your own functions that work with for ... range, and packages like maps and slices got new functions that use them. When you install Go yourself, you will get a newer version, so read the release notes to see what changed.
Keep practicing
The fastest way to improve is to solve many small problems. Slices, maps, strings.Builder and the sort and slices packages are the tools you will use most in coding interviews. Then build something bigger, like a command-line tool or a small web service. Many well-known tools, including Docker and Kubernetes, are written in Go, and their code is open for anyone to read.
In the exercise, choose the best way to protect a delivery-fee function from future mistakes.