liveBook · Manning

Go:embed directive

The go:embed directive is a Go compiler feature that incorporates specified file or directory contents into program variables and the compiled binary.

How 2 Manning books explain it

Learn Go with Pocket-Sized Projects

go:embed is a Go compiler directive that embeds the contents of files into variables during compilation.

How it is used
Loads separate template files into Go variables for web handlers without reading them on each call.
How deep it goes
Demonstrates string and filesystem embedding with template parsing, without detailing compiler internals or the full pattern rules.
Examples
Embeds an HTML index page, a set of HTML templates, and a CSS template.
What you can do after
Apply it via Go's embed package to load template files as a string or read-only filesystem.

Read how Learn Go with Pocket-Sized Projects explains go:embed directive →

Go by Example

File embedding is the Go compiler feature that incorporates external file contents into a program's variables and compiled binary.

How it is used
Packages deployment resources such as SQL schemas inside a Go binary so runtime execution needs no separate files.
How deep it goes
Explains compiler embedding, blank-import activation, string variables, embed.FS, and runtime database execution.
Examples
Uses a SQLite schema.sql file, a string variable, DB.ExecContext, and an embed.FS pattern for multiple SQL files.
What you can do after
Operate/configure deployments by embedding schemas and executing them without distributing separate SQL files.

Read how Go by Example explains go:embed directive →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.