A game server built with Nakama using Go runtime modules.
- Docker and Docker Compose
- Go 1.25.0 (for local development)
.
├── api/
│ ├── main.go # Go module with InitModule function
│ ├── go.mod # Go dependencies
│ ├── go.sum
│ ├── vendor/ # Vendored dependencies
│ ├── Dockerfile # Multi-stage build for Go plugin
│ └── local.yml # Nakama configuration
├── nakama/
│ └── data/ # Nakama data directory
├── docker-compose.yml # Docker services configuration
└── watch.sh # Auto-reload script
# Build and start all services
docker compose up --build
# Or run in detached mode
docker compose up -dThe server will be available at:
- gRPC:
localhost:7349 - HTTP API:
localhost:7350 - Console:
localhost:7351
# Follow all logs
docker compose logs -f
# Follow only Nakama logs
docker compose logs -f nakamadocker compose downAutomatically rebuilds and restarts when you modify Go files:
docker compose watchNow edit api/main.go and save - the server will automatically rebuild and restart.
If Docker Compose watch is not available:
# Terminal 1: Run services
docker compose up
# Terminal 2: Run watch script
./watch.sh# Rebuild and restart after code changes
docker compose build nakama
docker compose restart nakamaThe InitModule function in api/main.go is the entry point for your game logic:
func InitModule(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, initializer runtime.Initializer) error {
// Register RPCs, hooks, and other game logic here
logger.Info("Module initialized!")
return nil
}- Function signature must match exactly
- Use
package main - Import
github.com/heroiclabs/nakama-common/runtimefor Nakama APIs - All dependencies must be vendored (
go mod vendor)
cd api/
go get <package>
go mod tidy
go mod vendorThen rebuild the Docker container.
Edit api/local.yml to configure Nakama:
logger:
level: "DEBUG"See Nakama Configuration for all options.
PostgreSQL is included and automatically configured:
- Host:
postgres:5432(from Nakama container) - Database:
nakama - User:
postgres - Password:
localdb
Access from host machine: localhost:5432
Make sure your InitModule function has the correct signature with all parameters including db *sql.DB.
Ensure nakama-common version matches Nakama version:
- Nakama 3.35.1 requires
nakama-common v1.44.0
The Go version in the builder must match the runtime. Both are using Go 1.25.0.