TL;DR: A net/http service with a health endpoint, graceful shutdown and the port read from the environment, built by a two-stage Dockerfile into a 7 MB binary and an image around 15 MB. What it uses at runtime on 512 MB and a quarter of a CPU, how to add a database without adding bloat, how to embed static files in the binary, and what sleep looks like in the logs.
If a free container tier was designed for one language, it was Go. A Go web service compiles to a single static binary, starts in milliseconds and idles in a few tens of megabytes, so 512 MB and a quarter of a CPU is not a constraint, it is a surplus. This guide builds a small HTTP service the way it should be built for a container: a two-stage Dockerfile, a tiny image, a health endpoint, graceful shutdown, and the port read from the environment.
The service
Standard library only. net/http is enough for most services and it keeps the binary small.…