Skip to main content
Use app.Static(root, prefix) to map a URL prefix to a directory on disk. Lightning registers a wildcard route under that prefix and streams matching files directly to the client.

Basic Usage

This serves every file inside ./public under the /assets URL prefix: If a requested file does not exist, Lightning responds with 404 Not Found.

Absolute vs. Relative Paths

  • Relative path — resolved relative to the directory of the running executable, not the working directory. For example, "./public" is joined with the path to the compiled binary.
  • Absolute path — used as-is. Pass an absolute path when you want deterministic resolution regardless of where the binary lives.
During development you typically run go run main.go from your project root, so ./public resolves relative to the compiled temp binary’s directory, which may not be your project root. If files are not found, switch to an absolute path or embed assets with //go:embed.

Complete Example

Directory structure:
main.go:
With the server running, the following URLs serve the corresponding files:
You can register multiple static directories with different prefixes in the same application: