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.
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 HTML and CSS template files at compilation for HTTP handlers instead of reading them on each request.
- How deep it goes
- Works from a single embedded string through multi-file `embed.FS` parsing and named execution, without detailing compiler internals.
- Examples
- Uses an embedded `index.html`, a `templates/*.html` filesystem, and an embedded `styles.css` with color values.
- What you can do after
- Apply it via `//go:embed` to load single-file or multi-file templates and handle parsing and execution errors.
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.
Related concepts
- embedused by · The Go embed package is a standard-library package that embeds files and directories into compiled programs.
- os.Openalternative to · os.Open is a Go standard-library function that opens a named file for reading and returns a file handle and error.
- static fileused by · A static file is a preexisting digital resource served in its stored form rather than generated dynamically for each request.
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.

