- v1: checkout to the v1 branch
Function-based layer architecture with separate layers (domain, usecase, delivery, repository)
- 🏗️ Modular Architecture - Clean separation of concerns with store, service, and handler layers
- 🔐 JWT Authentication - Secure user authentication with middleware
- 🏥 Health Checks - Database and cache connectivity monitoring
- 📝 Request Logging - Comprehensive HTTP request logging
- ⚡ Caching - Redis integration for performance optimization
- 🧪 Testing - Unit and integration test coverage
- 🛡️ Middleware - CORS, recovery, real IP extraction, and request ID tracking
- 📊 Structured Logging - Using zerolog for structured, contextual logging
- 🔧 Configuration - Environment-based configuration management
- Go 1.22+ - Programming language
- GORM - ORM library for database operations
- PostgreSQL - Primary database
- Redis - Caching and session storage
- JWT - Authentication tokens
- Zerolog - Structured logging
- Testify - Testing framework
- Testcontainers - Integration testing with real containers
- go-playground/validator - Request validation
- go-redis - Redis client
- godotenv - Environment variables loader
- Go 1.22+
- Docker (for databases and integration tests)
- PostgreSQL (optional if using Docker)
- Redis (optional if using Docker)
-
Clone the repository
git clone https://github.com/syahidfrd/go-boilerplate.git cd go-boilerplate -
Install dependencies and format code
make tidy
-
Setup databases
# PostgreSQL docker run -d -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=go_boilerplate postgres # Redis docker run -d -p 6379:6379 redis
-
Configure environment
cp .env.example .env # Edit .env file with your configuration -
Run tests
# Unit tests make test/unit # Integration tests make test/integration # All tests make test/all
-
Run the application
# Option 1: Normal run make run bin=server # Option 2: Hot reload (development) make run/live bin=server
POST /api/auth/signup- User registrationPOST /api/auth/signin- User login
GET /api/todos- Get user's todosPOST /api/todos- Create new todoGET /api/todos/{id}- Get specific todoPUT /api/todos/{id}- Update todoPATCH /api/todos/{id}/toggle- Toggle completion statusDELETE /api/todos/{id}- Delete todo
GET /health- Service health status
This project includes comprehensive testing at multiple levels:
Run unit tests:
make test/unitRun integration tests with real PostgreSQL and Redis containers:
make test/integrationRequirements:
- Docker must be running
- Integration tests use Testcontainers to spin up real databases
make test/allYou can find all available commands in the Makefile:
make tidy- Format code and tidy dependenciesmake build- Build the application binarymake run bin=server- Build and run the applicationmake run/live bin=server- Run with live reload using Air
make test/unit- Run unit tests onlymake test/integration- Run integration tests (requires Docker)make test/all- Run all tests (unit + integration)