A production-ready boilerplate for building REST APIs with Go and Gin framework. This boilerplate includes essential features like database integration, API documentation, logging, error handling, and containerization support.
- Gin Framework for routing and middleware
- PostgreSQL integration with migration support
- Swagger API documentation
- API monitoring with APIToolkit
- Custom error handling and logging
- CORS configuration
- Docker and Docker Compose support
- OTP management system
- Static file serving
- Environment configuration
- Hot reload during development
- Code security scanning with gosec
- Event streaming with Apache Kafka
- Transactional message processing
- Consumer group management
- Event broadcasting system
- Go 1.x
- Docker and Docker Compose
- PostgreSQL (if running locally)
- Make
- Clone the repository
git clone https://github.com/CeoFred/gin-boilerplate.git
cd gin-boilerplate
- Copy the example environment file
cp .env.example .env
- Install dependencies
make requirements
Update the .env
file with your configuration:
PORT=8080
DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=yourpassword
DB_NAME=yourdatabase
API_TOOLKIT_KEY=your-api-toolkit-key
# Run the application with hot reload
make run-local
# Build the Docker image
make build
# Start all services using Docker Compose
make service-start
Swagger documentation is available at:
http://localhost:8080/swagger/index.html
To regenerate Swagger documentation:
make docs-generate
make run-local
- Run the application locally with hot reloadmake docs-generate
- Generate Swagger documentationmake requirements
- Install/update dependenciesmake clean-packages
- Clean Go module cachemake build
- Build Docker imagemake start-postgres
- Start PostgreSQL containermake stop-postgres
- Stop PostgreSQL containermake start
- Start application with Dockermake build-no-cache
- Build Docker image without cachemake service-stop
- Stop all Docker Compose servicesmake service-start
- Start all Docker Compose services
.
├── constants/ # Application constants and configuration
├── database/ # Database connection and migrations
├── docs/ # Swagger documentation
├── internal/
│ ├── bootstrap/ # Application bootstrapping
│ ├── helpers/ # Helper functions
│ ├── otp/ # OTP management
│ ├── repository/ # Repository management
│ ├── routes/ # API routes
│ └── streaming/ # Kafka streaming implementation
│ ├── consumer.go # Kafka consumer implementation
│ ├── producer.go # Kafka producer implementation
│ └── events.go # Event type definitions
├── static/ # Static files
├── templates/ # Template files
├── main.go # Application entry point
├── Dockerfile # Docker configuration
├── docker-compose.yml # Docker Compose configuration
└── Makefile # Build and development commands
The project includes security measures:
- Custom recovery middleware
- CORS configuration
- Request logging
- Security scanning with gosec
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.
Johnson Awah Alfred - [email protected]
Give a ⭐️ if this project helped you!