//go:embed
Go 1.16 introduced a new //go:embed
directive that allows you to include the contents of arbitrary files and directories in your Go application.
The basic idea of embedding is that by adding a special comment to your code, Go will know to include a file or files. The comment should look like //go:embed FILENAME(S)
and be followed by a variable of the type you want to embed: string
or []byte
for an individual file or embed.FS
for a group of files.
The go:embed directive understands Go file globs, so patterns like files/.html will also work (but not **/.html recursive globbing).
You can read the official docs embed · pkg.go.dev - https://pkg.go.dev/embed for a complete technical explanation, so here let’s take a look at some examples to see what’s possible.