- Go 1.22+
- Docker & Docker Compose
- Make
- SQLC (
go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest) - Goose (
go install github.com/pressly/goose/v3/cmd/goose@latest) - Swag (
go install github.com/swaggo/swag/cmd/swag@latest)
# Clone the repository
git clone <repo-url>
cd go-codebase
# Install dependencies
go mod tidy
# Start infrastructure
make docker-up
# Run migrations
make migrate-up
# Seed default roles and permissions
make seed
# Generate SQLC code
make sqlc
# Start the server
make runThe server starts at http://localhost:8080.
- Swagger UI:
http://localhost:8080/swagger/index.html - Health check:
http://localhost:8080/health
| Command | Description |
|---|---|
make run |
Start the API server |
make build |
Build the binary |
make test |
Run all tests |
make test-coverage |
Run tests with coverage |
make lint |
Run linter |
make fmt |
Format code |
make migrate-up |
Run database migrations |
make migrate-down |
Rollback migrations |
make sqlc |
Generate SQLC code |
make swagger |
Generate Swagger docs |
make seed |
Seed default roles and permissions |
make docker-up |
Start Docker services |
make docker-down |
Stop Docker services |
# Run all tests
make test
# Run with coverage
make test-coverage
# Run specific package
go test ./internal/todo/...Configuration is loaded from (in order):
configs/config.yaml- Environment variables
Environment variables override config file values. See .env.example for available variables.
After modifying SQL queries in queries.sql:
make sqlcAfter modifying swagger annotations in handler files:
make swaggerThis regenerates docs/docs.go, docs/swagger.json, and docs/swagger.yaml.
Create a new migration:
goose -dir migrations create <name> sql- Register a user via
POST /api/v1/auth/register - Use the returned access token in the
Authorization: Bearer <token>header - When the token expires, call
POST /api/v1/auth/refreshwith the refresh token
- Create roles via
POST /api/v1/auth/roles - Create permissions via
POST /api/v1/auth/permissions - Assign permissions to roles via
POST /api/v1/auth/roles/{roleId}/permissions - Assign roles to users via
POST /api/v1/auth/users/{userId}/roles - The seed script creates default roles:
admin,user
See Architecture.md