pengfeidai / gin-app-start

A development framework based on Gin, which provides a clear directory structure and powerful features. It includes commonly used middleware such as parameter validation and exception handling, as well as utility methods like HTTP request encapsulation and email services. It also supports databases like MySQL, MongoDB, and Redis.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

gin-app-start

基于 Gin 封装的开发框架,目录结构清晰,功能强大,包含了一些常用中间件,如:参数校验、异常捕获等;常用方法:http请求封装,邮件服务等;支持Mysql、Mongodb、Redis等数据库。

持续更新...

目录结构

该目录结构是结合自己之前写 nodejs 的工作经验来的,其中也是参考了 egg.js 的目录结构,自认为结构还是比较清晰,一目了然,也欢迎大家提出好的建议,共同学习。

gin-app-strat
├── app
|    ├── common // constant定义、errorCode等
|    ├── config // 定义config的struct,路由加载
|    |     └── config.go
|    ├── controller
|    ├── database // mysql、mongo、redis等
|    ├── middleware // 中间件
|    ├── model
|    ├── public // 静态资源
|    ├── router // 路由分组、路由聚合加载
|    ├── schema // 定义controller中使用的struct,用于参数绑定、校验
|    ├── service 
|    ├── util  // 常用方法
├── logs
|   ├── access.log
|   └── error.log
├── test  // 测试用例
|   ├── controller
|   ├── service
|   └── model
├── .gitignore
├── config.yaml  // 配置文件
├── Dockerfile
├── go.mod
├── go.sum
├── main.go // 启动文件
└── README.md

功能点

  • 使用 go modules 初始化项目
  • 安装 Gin 框架
  • 支持优雅地重启或停止
  • 规划项目目录
  • 路由
    • 分组、聚合
    • 路由中间件
  • Session
    • cookie-based
    • Redis
  • 存储
  • 常用方法
    • http请求封装
    • 常用方法util.go,如:uuid
    • 发送邮件
  • 线上部署
    • dockerfile
    • 自定义配置文件

快速开始

代码仓库

git clone git@github.com:pengfeidai/gin-app-start.git

环境配置

  • Go version >= 1.13
  • Global environment configure
export GO111MODULE=on
// 修改代理
export GOPROXY=https://goproxy.io
// go env -w GOPROXY=https://goproxy.cn,direct 

服务启动

cd gin-app-start

// 本地启动
SERVER_ENV=local go run main.go

输出如下 `Listening and serving HTTP on Port: :9060, Pid: 15932`表示 Http Server 启动成功

健康检查

curl -X GET http://127.0.0.1:9060/health_check?name=world

线上部署

线上部署建议使用 docker 方式部署,详细可以参考 dockerfile 文件,配置文件支持 命令行 或者 环境变量 的方式。

About

A development framework based on Gin, which provides a clear directory structure and powerful features. It includes commonly used middleware such as parameter validation and exception handling, as well as utility methods like HTTP request encapsulation and email services. It also supports databases like MySQL, MongoDB, and Redis.


Languages

Language:Go 93.3%Language:Makefile 3.7%Language:Dockerfile 3.0%