Build And Deploy

Unpack Assets

Write embedded assets to disk for platforms that need static files.

By Guillermo Alvarez - Published - Updated

Prefer serving from the binary

Most deployments can let the GoLazy binary serve embedded public files. That keeps deployment simple:

go build -o .tmp/build/app ./cmd/app
ADDR=0.0.0.0:8080 .tmp/build/app

No public directory is required beside the binary.

Unpack for static-file platforms

If a platform needs files on disk, call the asset registry:

if err := appinit.App().Assets.Unpack(
    "public",
    lazyassets.WithUnpackMode(lazyassets.UnpackPermanent),
); err != nil {
    log.Fatal(err)
}

This writes registered public assets to the target directory.

Choose a mode

Use the mode that matches the deployment target:

lazyassets.UnpackBoth
lazyassets.UnpackLogical
lazyassets.UnpackPermanent

UnpackPermanent writes content-hashed paths for long-lived cache headers. UnpackLogical writes only logical paths such as /styles.css. UnpackBoth writes both forms.

Keep unpacking separate from serving

Unpacking is a deployment step, not a requirement for GoLazy to serve assets. The application can still serve embedded assets directly through its HTTP handler.