Svelte + Fiber on Netlify
A Go Fiber API deployed as a Netlify Function, with a Svelte frontend. The API provides IP geolocation via ip-api.com.
Demo: https://gofiber-svelte.netlify.app/
Prerequisites
- Go 1.21+
- Node.js 18+ (for the Svelte frontend)
- Netlify CLI —
npm install -g netlify-cli
Local Development
-
Install frontend dependencies and build the Svelte app:
npm installnpm run build -
Build the Go function:
./build.sh -
Start the local dev server:
netlify devThe app will be available at
http://localhost:8888.
Deploy to Netlify
Via Netlify CLI
netlify deploy --prod
Via Git
Connect your repository in the Netlify dashboard. The netlify.toml configures the build automatically.
How It Works
./build.shcompiles the Go binary tocmd/gateway/gatewayand places it in thefunctions/directory.- Netlify serves the binary as a Netlify Function.
- Static files under
public/are served directly (entry point:index.html). - API calls to
/api/*are redirected server-side to/.netlify/functions/gateway/:splat(status 200).
Project Structure
.
├── adapter/ # AWS Lambda <-> Fiber adapter
├── cmd/gateway/ # Lambda entry point (main.go)
├── handler/ # Fiber route handlers
├── public/ # Compiled Svelte frontend
├── build.sh # Build script for the Go function
└── netlify.toml # Netlify build configuration
Notes
- Netlify Functions are limited to 125,000 requests/month on the free tier (~2.89 req/min). Response caching with a 10-minute TTL is applied to the geolocation endpoint to stay within limits.