Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-gin-pattern

Example clean-architecture backend implemented with Go and Gin.

Overview

go-gin-pattern is a small example backend demonstrating a clean architecture style using the Gin web framework. It provides a minimal, opinionated layout for configuration, logging, middleware, handlers, services, repositories, and seeding.

Features

  • Structured project layout following a clean architecture pattern
  • Configuration via viper
  • Structured logging with logrus
  • Request middleware (request ID, logging)
  • Simple health check handler and service
  • Seeder support and repository/service layers

Architecture

The project separates responsibilities into clear packages: configuration (app/), handlers (handler/), services (service/), repositories (repository/), models (model/), middleware (middleware/), and helpers (helper/). This keeps HTTP, business logic, and persistence concerns decoupled.

Getting Started

Prerequisites:

  • Go 1.20+ installed

Clone the repository and run:

go run main.go

By default the server reads configuration from the app/config files (Viper). Adjust settings there or via environment variables as needed.

Configuration

Configuration is centralized in app/config and loaded with viper. Common settings include server port, database connection, and logging level. See app/config/app.go and app/config/viper.go for details.

Project Layout

  • app/ — application bootstrap and config
  • handler/ — HTTP handlers
  • service/ — business logic
  • repository/ — data access
  • model/ — data models
  • middleware/ — HTTP middleware
  • helper/ — shared helpers (pagination, response, validator)
  • logs/ — runtime logs

Logging

Logging is implemented with logrus and configured in app/logrus.go. Logs are written to the logs/ folder by default.

Seeders

Seeders live in seeder/ and can be extended to populate initial data into the database when needed.

Contributing

Contributions are welcome. Open an issue or submit a pull request with a clear description of the change.

License

This project is provided as-is. Add a license file if you intend to publish or share under a specific license.

About

🔥 Clean architecture REST API by Go/Gin

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages