Route-Level Go Logic
Power your pages with Go-based logic directly within each route.
Server Logic
index.server.go enables routes to run native Go code before rendering HTML. You can fetch data, compute values, or perform request-based logic - all without extra frameworks or boilerplate.What Are Server Files?
Each route in Barry can include an index.server.go
file that runs on the server before rendering your index.html
. This file lets you:
- Load data from APIs, databases, or files
- Use request parameters (e.g. slugs, IDs)
- Generate dynamic content
- Populate templates with structured values
Once the HTML is rendered with the data from your handler, Barry caches the result to disk for instant delivery. See Page Caching for details.
When Should You Use Server Files?
You only need a server file when a page:
- Varies based on request data (e.g., slug, query param, header)
- Needs to fetch or transform content before rendering
- Requires secure, server-side logic
If a route has fixed, static content, you can skip the server file entirely and use index.html
alone.
Server files work beautifully with Barry’s dynamic routing - where parameters like _slug
become available in the request context.