Skip to content

A simple and flexible layout structure for building Go applications with Gin framework. This project provides an easy-to-use base structure, integrating common patterns like global context, routing, and modular internal packages to speed up the development of scalable and maintainable applications.

Notifications You must be signed in to change notification settings

tic8/go-gin-layout

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-gin-layout

项目简介

go-gin-layout 是一个基于 Gin 框架的 Go 项目模板,集成了常用的功能和工具,旨在帮助开发者快速构建高效、可维护的 Web 应用程序。

功能特性

  • 配置管理:使用 Viper 进行灵活的配置管理。
  • 日志记录:集成 Zap 提供高性能日志记录。
  • 数据库支持:使用 GORM 和 MySQL 驱动进行数据库操作。
  • Redis 集成:支持 Redis 缓存,使用 go-redis
  • JWT 认证:集成 golang-jwt 实现用户认证。
  • 定时任务:支持基于 Cron 的定时任务调度。
  • Swagger 文档:集成 Swaggo 自动生成 API 文档。
  • Prometheus 监控:支持 Prometheus 指标监控。

快速开始

环境要求

  • Go 1.23 或更高版本
  • MySQL 数据库
  • Redis 缓存

安装依赖

go mod tidy

配置文件

修改 config.yaml 文件,根据实际需求调整以下配置:

server:
  port: 8080

database:
  dsn: root:password@tcp(127.0.0.1:3306)/your_database?charset=utf8mb4&parseTime=True&loc=Local

redis:
  addr: localhost:6379
  password: ""
  db: 0

jwt:
  secret: your_jwt_secret
  expire: 3600

启动项目

go run cmd/main.go

启动后,服务将运行在 http://localhost:8080

Swagger 文档

访问 http://localhost:8080/swagger/index.html 查看自动生成的 API 文档。

Prometheus 指标

访问 http://localhost:8080/metrics 查看 Prometheus 指标。

项目结构

go-gin-layout/
├── cmd/                # 主程序入口
├── internal/           # 内部模块
│   ├── config/         # 配置管理
│   ├── handler/        # 路由处理
│   ├── middleware/     # 中间件
│   ├── model/          # 数据模型
│   ├── service/        # 业务逻辑
│   └── util/           # 工具函数
├── config.yaml         # 配置文件
├── go.mod              # 依赖管理
├── README.md           # 项目说明

依赖列表

主要依赖:

贡献

欢迎提交 Issue 和 Pull Request 来改进本项目。

许可证

本项目基于 MIT License 开源。

About

A simple and flexible layout structure for building Go applications with Gin framework. This project provides an easy-to-use base structure, integrating common patterns like global context, routing, and modular internal packages to speed up the development of scalable and maintainable applications.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published