gin-boilerplate

command module
v0.0.0-...-9aa584b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2024 License: MIT Imports: 28 Imported by: 0

README ΒΆ

Gin Boilerplate

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.

πŸš€ Features

  • 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

πŸ“‹ Prerequisites

  • Go 1.x
  • Docker and Docker Compose
  • PostgreSQL (if running locally)
  • Make

πŸ› οΈ Installation

  1. Clone the repository
git clone https://github.com/CeoFred/gin-boilerplate.git
cd gin-boilerplate
  1. Copy the example environment file
cp .env.example .env
  1. Install dependencies
make requirements

πŸ”§ Configuration

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

πŸš€ Running the Application

Local Development
# Run the application with hot reload
make run-local
Using Docker
# Build the Docker image
make build

# Start all services using Docker Compose
make service-start

πŸ“š API Documentation

Swagger documentation is available at:

http://localhost:8080/swagger/index.html

To regenerate Swagger documentation:

make docs-generate

πŸ› οΈ Available Make Commands

  • make run-local - Run the application locally with hot reload
  • make docs-generate - Generate Swagger documentation
  • make requirements - Install/update dependencies
  • make clean-packages - Clean Go module cache
  • make build - Build Docker image
  • make start-postgres - Start PostgreSQL container
  • make stop-postgres - Stop PostgreSQL container
  • make start - Start application with Docker
  • make build-no-cache - Build Docker image without cache
  • make service-stop - Stop all Docker Compose services
  • make service-start - Start all Docker Compose services

πŸ“ Project Structure


.
β”œβ”€β”€ 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

πŸ”’ Security

The project includes security measures:

  • Custom recovery middleware
  • CORS configuration
  • Request logging
  • Security scanning with gosec

🀝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the Apache 2.0 License - see the LICENSE file for details.

πŸ‘€ Contact

Johnson Awah Alfred - johnsonmessilo19@gmail.com

⭐️ Show your support

Give a ⭐️ if this project helped you!

Documentation ΒΆ

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL