embed
Coreimport "embed"Provides access to files embedded in the Go program at compile time (Go 1.16+).
Example
package main
import (
"embed"
"fmt"
)
//go:embed hello.txt
var content string
func main() {
fmt.Println(content)
}Key Types & Functions
FSReadDirReadFileAbout embed
The embed package (imported as embed) belongs to the Core category of Go packages. Provides access to files embedded in the Go program at compile time (Go 1.16+).
Go's standard library is one of the language's greatest strengths, providing production-ready implementations for networking, cryptography, encoding, I/O, and more. The embed package follows Go's philosophy of simplicity and composability — small, focused packages that combine through interfaces like io.Reader and io.Writer.
When using embed in production, follow Go best practices: handle errors explicitly, use context for cancellation and timeouts, prefer composition over inheritance, and write table-driven tests. The Go documentation at pkg.go.dev provides comprehensive API references and examples for every exported type and function.