A production-ready Go microservice template with built-in authentication, configuration management, and health checks.
- Clean architecture with proper separation of concerns
- Configuration management using Viper
- Authentication middleware with Keycloak integration
- PostgreSQL database integration using pgx
- Health check endpoints
- Docker and Docker Compose support
- Comprehensive test suite
- Makefile for common operations
- Go 1.21 or higher
- Docker and Docker Compose
- PostgreSQL
- Make (optional, for using Makefile commands)
.
├── cmd/
│ └── server/
│ └── main.go
├── config/
│ ├── config.go
│ ├── database/
│ └── router/
├── internal/
│ ├── app/
│ ├── handler/
│ ├── service/
│ └── repository/
├── resources/
│ ├── config.yaml
│ ├── config-local.yaml
│ ├── config-stg.yaml
│ └── config-prod.yaml
├── Dockerfile
├── docker-compose.yml
├── Makefile
└── README.md
- Clone the repository:
git clone https://github.com/your-username/your-service.git
cd your-service- Install dependencies:
go mod download- Set up configuration:
cp resources/config-local.yaml resources/config.yaml
# Edit config.yaml with your settings- Start the development environment:
make compose-up- Run the application:
make devThe application uses a hierarchical configuration system:
- Default configuration in
resources/config.yaml - Environment-specific configurations:
config-local.yamlconfig-stg.yamlconfig-prod.yaml
- Environment variables override (prefixed with
APP_)
Run the test suite:
make test- Build Docker image:
make docker-build- Run with Docker Compose:
make compose-upmake build: Build the applicationmake test: Run testsmake run: Run the application locallymake docker-build: Build Docker imagemake docker-run: Run Docker containermake compose-up: Start all servicesmake compose-down: Stop all servicesmake lint: Run lintermake mock: Generate mocks for testingmake migrate-up: Run database migrationsmake migrate-down: Rollback database migrations
The service provides a health check endpoint at /health that monitors:
- Application status
- Database connectivity
- Authentication service status
Authentication is handled via a auth service. Configure the following in your environment:
- Keycloak URL
- Realm
- Client ID and Secret
- Resource permissions