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
Pass embedded resources to lazyapp.New during application startup:
func App() *lazyapp.App {
return lazyapp.New(lazyapp.Config{
Name: "sample_app",
Drawer: Draw,
Public: app.Public,
Views: app.Views,
Context: Context,
})
}
lazyapp.New opens and validates views before serving requests. Public files
are served by dispatch after route lookup.
Build one binary
Build the executable with ordinary Go:
go build ./cmd/app
That command uses Go's default output name. In the sample application the
default name is app, which would collide with the existing app/ directory,
so choose an explicit artifact path for production:
go build -o /tmp/sample-app ./cmd/app
Run it:
/tmp/sample-app
No template or public directory is required beside the binary. Views, layouts, public files, and other embedded resources are compiled into the executable.
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.