Go embed: Prod Binary, Dev Live Files
- Published
- Duration
- Language
- English
Summary
Go's embed package makes production easy — one binary with assets inside. Development hurts when every CSS or template change needs a rebuild. This explainer shows the fs.FS pattern: embed.FS in prod, os.DirFS in dev, same FileServer and ParseFS, via build tags or a runtime switch. Verified with Go 1.27.3.
Transcript
Text of the video's narration.
embed is easy in prod. Dev is where it hurts. Let me show you. In production, go colon embed copies your static files into the binary at build time. Delete the static folder on the server and the site still serves. One file to ship.
In development, that copy is frozen. Every CSS tweak means another build. Your gopher starts drinking coffee professionally. The fix is not more magic. Program against io/fs.FS, not embed.FS itself. One file, tagged not dev, embeds the tree and trims it with fs.Sub.
Another file, tagged dev, returns os.DirFS. Same function. Same FileServer. Same ParseFS. Run with dash tags dev, edit, refresh: the file server reads from disk. Templates too, if you parse them per request in dev. Or flip it at runtime, Brandur style: production uses the embed, everything else reads disk.
One gotcha: DirFS paths follow your working directory, not your package. Speak fs.FS. Embed for the ship. Disk for the loop.
Sources
- embed pkg.go.dev
- io/fs pkg.go.dev
- Go 1.16 go.dev
- Brandur, go:embed in prod / disk in development brandur.org
- Go gopher by Renée French, CC BY 4.0 go.dev
Credits and notes
- Visuals and narration generated with AI tools.



