Build And Deploy

Build One Binary

Embed views, public files, generated assets, and content into one Go executable.

By Guillermo Alvarez - Published Updated

Embed application resources

GoLazy applications use embed.FS for views and public files:

//go:embed views public
var Files embed.FS

var Views = lazyapp.MustSub(Files, "views")
var Public = lazyapp.MustSub(Files, "public")

Services can use the same pattern for embedded Markdown or other application content:

//go:embed content/*.md
var content embed.FS

Pass resources to lazyapp

Startup gives the embedded views and public files to lazyapp.New:

func App() *lazyapp.App {
    return lazyapp.New(lazyapp.Config{
        Name:    "sample_app",
        Drawer:  Draw,
        Public:  app.Public,
        Views:   app.Views,
        Context: Context,
    })
}

lazyapp.New validates views, registers public files with lazyassets, and returns one http.Handler application.

Generate assets before building

Generated assets must exist under public files before Go embeds them. Run the asset commands that match the files you changed:

lazy tailwind
lazy js

Tailwind writes:

app/public/styles.css

lazy js writes:

app/public/assets/importmap.json
app/public/assets/lazyshaft/*.js

Those files are embedded into the production binary like any other public file.

Build the executable

Build with ordinary Go:

go build -o .tmp/build/sample-app ./cmd/app

Run it:

ADDR=127.0.0.1:4000 .tmp/build/sample-app

No views or public directory is required beside the binary. The compiled executable already contains the embedded bytes.

Rebuild after embedded changes

Rebuild the binary after changing:

  • views or layouts;
  • public files;
  • Tailwind input or output;
  • JavaScript source, manifest, package files, or generated lazyshaft assets;
  • embedded Markdown or other service-owned content.

During development, lazy watches these files and restarts the temporary app after successful rebuilds. Direct go run ./cmd/app processes and production binaries still need a manual restart.

Use Deployment for runtime address and production smoke checks.