embed
The Go package and //go:embed comment that build files such as templates or static assets into the binary at compile time.
In more detail
A variable marked with //go:embed receives the file contents when you build, so the program does not need those files next to it at run time. This keeps a static binary truly self-contained, which suits scratch images.
Example
//go:embed index.html
var page stringRelated terms
- static binary — A program file that carries all the code it needs inside it and loads no shared libraries from the machine it runs on.
- scratch — Docker's special empty base image, with no files at all, used to ship a single static binary and nothing else.
Taught in
- Building Static Binaries — Concurrent Systems Programming with Go