A modern Go REST API server following best practices with clean architecture, comprehensive testing, and Docker support.
- 🚀 RESTful API server using Gin framework
- ✅ Comprehensive unit tests with high coverage
- 🔍 Linting with golangci-lint (Docker support)
- 🐳 Docker support for containerized deployment
- 📦 Modern project structure following Go best practices
- 🔧 Makefile for common development tasks
- ⚡ Graceful shutdown support
- 📝 Clean code architecture
.
├── cmd/
│ └── server/ # Application entry point
├── internal/
│ ├── api/ # API route setup
│ ├── handlers/ # HTTP handlers
│ └── models/ # Data models
├── pkg/ # Public library code
├── bin/ # Build artifacts
├── Makefile # Build automation
├── .golangci.yml # Linter configuration
├── Dockerfile # Docker image definition
├── go.mod # Go module definition
└── README.md # This file
- Go 1.23 or later
- Docker (optional, for linting)
- Make (optional, for using Makefile)
make install
# or
go mod downloadmake run
# or
go run cmd/server/main.goThe server will start on http://localhost:8080 by default.
make build
# or
go build -o bin/server ./cmd/servermake test
# or
go test ./...make test-coveragemake lintmake lint-localGET /health
Returns the health status of the service.
Response:
{
"status": "ok",
"service": "go-api-server"
}GET /api/v1/users
GET /api/v1/users/:id
POST /api/v1/users
Content-Type: application/json
{
"name": "John Doe",
"email": "john@example.com"
}
DELETE /api/v1/users/:id
PORT: Server port (default: 8080)ENV: Environment mode (development/production, default: development)
Run make help to see all available commands:
make build- Build the applicationmake run- Run the applicationmake test- Run testsmake test-coverage- Run tests with coverage reportmake lint- Run linter using Dockermake lint-local- Run linter locallymake fmt- Format codemake vet- Run go vetmake install- Install dependenciesmake clean- Clean build artifactsmake ci- Run CI checks (lint + test)
This project uses Colima (headless Docker daemon) for Docker support. See SETUP.md for Docker installation instructions.
make docker-build
# or
docker build -t go-api-server:latest .make docker-run
# or
docker run -p 8080:8080 go-api-server:latestdocker-compose up
# or in detached mode
docker-compose up -d- Follow Effective Go guidelines
- Run
make fmtbefore committing - Ensure
make lintpasses - Write tests for new features
- All tests should be in
*_test.gofiles - Use the standard
testingpackage - Use
testifyfor assertions - Aim for >80% test coverage
MIT