Building for production
Go compiles your entire application into a single binary with no external dependencies. This makes deployment simple.Basic build
app for your current operating system.
Cross-compile for Linux
If you’re building on macOS or Windows for a Linux server:| Flag | Purpose |
|---|---|
GOOS=linux | Target operating system |
GOARCH=amd64 | Target architecture (64-bit Intel/AMD) |
-ldflags="-s -w" | Strip debug info (smaller binary) |
-o app | Output filename |
Method 1: Direct server deployment
The simplest approach—upload and run.Upload the binary
Run manually (testing)
Run with systemd (production)
To keep your app running after logout and auto-restart on crashes, create a systemd service. Create/etc/systemd/system/myapp.service:
Method 2: Docker deployment
Docker packages your app with its runtime environment for consistent deployments.Dockerfile
Create aDockerfile in your project root:
Build and run
Docker Compose
For apps with dependencies (databases, etc.), usedocker-compose.yml:
HTTPS with reverse proxy
Don’t expose your Go app directly to the internet. Use a reverse proxy for:- Automatic HTTPS certificates
- Load balancing
- Rate limiting
- Static file serving
Caddy (easiest)
Caddy automatically obtains and renews TLS certificates. Install Caddy, then create/etc/caddy/Caddyfile:
https://myapp.example.com.
Nginx
For more control, use Nginx with certbot for certificates./etc/nginx/sites-available/myapp:
Health checks
Mizu provides health check handlers for load balancers and orchestrators./readyz. During graceful shutdown, it returns 503, allowing the load balancer to drain traffic before the server stops.
Graceful shutdown
Mizu handles graceful shutdown automatically. When your app receives SIGINT (Ctrl+C) or SIGTERM (from systemd, Docker, or Kubernetes):- New connections are refused
- Active requests complete (up to timeout)
- Server exits cleanly
Environment variables
Read configuration from environment variables for different environments:Checklist
Before deploying to production:- Build with
-ldflags="-s -w"for smaller binary - Set up a reverse proxy (Caddy or Nginx) for HTTPS
- Configure systemd or Docker for auto-restart
- Set up health check endpoints
- Configure graceful shutdown timeout
- Set up log aggregation
- Test graceful shutdown locally