Digging Deeper
Embedding and Deployment
Package templates, public files, and content into one executable and configure it at runtime.
Embed application resources
GoLazy applications use embed.FS:
//go:embed views public
var Files embed.FS
Sub-filesystems keep consumers scoped:
func Views() (fs.FS, error) {
return fs.Sub(Files, "views")
}
func Public() (fs.FS, error) {
return fs.Sub(Files, "public")
}
Services can use the same pattern for embedded Markdown or other application content.
Initialize embedded files
Open and validate embedded resources during application startup:
views, err := app.Views()
if err != nil {
panic(fmt.Errorf("open embedded views: %w", err))
}
renderer, err := controller.NewRenderer(views)
if err != nil {
panic(fmt.Errorf("initialize renderer: %w", err))
}
Failing early prevents a server from starting with incomplete templates or assets.
Build one binary
Build the executable:
go build -o /tmp/sample-app ./cmd/app
Run it:
/tmp/sample-app
No template or public directory is required beside the binary.
Configure the address
The sample executable reads ADDR:
ADDR=3000 /tmp/sample-app
ADDR=127.0.0.1:3000 /tmp/sample-app
A numeric value is treated as a port. A full value is passed directly to
http.Server.
Runtime configuration beyond ADDR belongs to the application until the
framework defines a stable configuration API.
Rebuild on file changes
Embedded files are compiled into the executable. After changing:
- Views.
- Layouts.
- Public files.
- Embedded Markdown.
rebuild or restart go run.
Restart go run ./cmd/app after changing embedded resources.
Deployment checklist
Before deployment:
- Run tests, race tests, and
go vet. - Build the exact commit being deployed.
- Start the binary with the production listen address.
- Request the home page and at least one public asset.
- Confirm logs and process supervision are configured by the deployment environment.
GoLazy intentionally leaves TLS termination, process supervision, and platform configuration to the deployment environment and the Go standard library.