Embed a single file as a string
import _ "embed"
//go:embed version.txt
var version string
fmt.Println(version)
embedEmbed files and directories into your binary at build time. No external assets at runtime.
import _ "embed"
//go:embed version.txt
var version string
fmt.Println(version)
//go:embed logo.png
var logo []byte
Pass to http.FileServerFS, template.ParseFS, fs.Sub, fs.WalkDir — anywhere that takes an fs.FS.
import "embed"
//go:embed templates static
var assets embed.FS
tmpl := template.Must(template.ParseFS(assets, "templates/*.html"))
static, _ := fs.Sub(assets, "static")
mux.Handle("GET /static/", http.StripPrefix("/static/", http.FileServerFS(static)))
//go:embed *.sql migrations/*
var schema embed.FS
The line just above the var must be the //go:embed directive. No blank line between them.