Skip to main content
Mizu can serve static files such as images, CSS, and JavaScript using the Static method on the router.
You can serve files from a local directory or from Go’s embedded filesystem.

Serve files from a local directory

If you have a public/ folder containing assets:
app := mizu.New()
app.Static("/assets/", http.Dir("public"))
app.Listen(":3000")
This makes public/logo.png available at http://localhost:3000/assets/logo.png. You do not have to include the trailing slash in the prefix — Mizu automatically adds it internally.

Serve embedded files

You can include static files directly in your Go binary using the embed package. To serve files correctly, use fs.Sub to remove the folder prefix.
import (
	"embed"
	"io/fs"
	"net/http"
	"github.com/go-mizu/mizu"
)

//go:embed public/*
var publicFS embed.FS

func main() {
	app := mizu.New()

	sub, err := fs.Sub(publicFS, "public")
	if err != nil {
		panic(err)
	}

	app.Static("/assets/", http.FS(sub))
	app.Listen(":3000")
}
This serves /assets/logo.png from the embedded file public/logo.png.

Mount external handlers

You can mount any standard http.Handler at a specific path. This works well with http.FileServer or other middleware built for net/http.
fs := http.FileServer(http.Dir("uploads"))
app.Mount("/files", http.StripPrefix("/files", fs))
Mizu’s Static method works the same way internally, using http.FileServer and http.StripPrefix to ensure correct path handling.