Greetings. There are lots of libraries like this. For better or worse, I made yet another one
GitHub: https://github.com/lassik/airfreight
Example of usage: https://github.com/lassik/airfreight/tree/master/example
This library is made from the ground up for go.mod
projects. You add a trivial helper program to your project, such as staticgen/main.go
. This helper program calls airfreight’s packer API to pack your static assets into one or more auto-generated .go
files. Your project’s real main program refers to the helper via //go:generate go run staticgen/main.go
. You then only need to run go generate && go build
to build your project. Thanks to the Go’s new module system you don’t need to worry about how to download or install airfreight or how go generate
can find its packer executable – all of that just works.
The other main features:
- Extremely lightweight (hence the name).
- Designed to be as composable as possible (e.g. the generated files essentially just contain maps of strings, and you can lay out your static files and Go files however you like).
- Has no configuration options. You describe your static maps in
staticgen/main.go
and commit that file to version control; then just rungo generate
and you’ll always get the same behavior. There is e.g. no “developer mode” for live-reloading of code.
The motivation for making this library is that I used some of the other ones for a while and their complex behavior kept getting in the way of writing and shipping an application. This one does as much as possible to get our of your way. The downside is that it doesn’t have as many features.