# README
Go Microservice Template
A production-ready Go microservice template with built-in authentication, configuration management, and health checks.
Features
- 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
Prerequisites
- Go 1.21 or higher
- Docker and Docker Compose
- PostgreSQL
- Make (optional, for using Makefile commands)
Project Structure
.
├── 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
Getting Started
- 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 dev
Configuration
The application uses a hierarchical configuration system:
- Default configuration in
resources/config.yaml
- Environment-specific configurations:
config-local.yaml
config-stg.yaml
config-prod.yaml
- Environment variables override (prefixed with
APP_
)
Testing
Run the test suite:
make test
Deployment
- Build Docker image:
make docker-build
- Run with Docker Compose:
make compose-up
Available Make Commands
make 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
Health Check
The service provides a health check endpoint at /health
that monitors:
- Application status
- Database connectivity
- Authentication service status
Authentication
Authentication is handled via a auth service. Configure the following in your environment:
- Keycloak URL
- Realm
- Client ID and Secret
- Resource permissions
END
# Packages
No description provided by the author