Simple web app with Go
By Mikael Ståldal
I have been learning the Go programming language lately, and it’s remarkably easy to build simple web apps with it. In particular, with just a few simple tricks, you can make the deployment of such web apps super simple: just one single standalone statically linked binary which stores its data in one single file.
The Go standard library contains everything needed to build a basic web app:
- A production-ready HTTP server
- An URL router
- Interface for SQL databases
- Parsing command line options
- Simple logging
- HTML templating
- HTTP client
If you use the embed feature, you can embed templates and static resources (CSS, JavaScript, images) and produce one single self-contained binary.
If you build with go build -tags netgo, and otherwise avoid cgo, you can build a statically linked binary on Linux.
In Go, it’s straightforward to use SQLite as the relational database; you can store your data in one single file with a well-defined format and zero configuration. I recommend this SQLite implementation for Go which doesn’t rely on cgo.