Skip to content

Latest commit

 

History

History
109 lines (89 loc) · 3.22 KB

README.md

File metadata and controls

109 lines (89 loc) · 3.22 KB

Gin Web Example

An example of gin web project, using Gin、Gorm、MySQL、Redis etc

简体中文 | English

How to run

Required

  • MySQL
  • Redis

Ready

  1. Start MySQL & Redis
  2. Create three databases: ordin、inspection、risk
mysql -uroot -prootroot -e "CREATE DATABASE IF NOT EXISTS ordin DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;CREATE DATABASE IF NOT EXISTS inspection DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;CREATE DATABASE IF NOT EXISTS risk DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;"

Conf

You should modify conf/config.dev.toml

[database]
Type = mysql
User = root
Password = rootroot
Host = 127.0.0.1:3306
ODBName =  ordin 
IDBName = inspection 
RDBName = risk

[redis]
Host = 127.0.0.1:6379
Password = ""
db = 0
pool_size = 100

Run

Specify the configuration file go run main.go -c conf/config.dev.toml,or run the air command to live reload for server,useful for development and debugging

$ git clone https://github.com/anzhihe/gin-web-example.git

$ cd gin-web-example

$ go run main.go or make run or air

Project information and existing API

[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
 - using env:	export GIN_MODE=release
 - using code:	gin.SetMode(gin.ReleaseMode)

[GIN-debug] GET    /health                   --> thor-backend/internal/controller.(*Server).health-fm (3 handlers)
[GIN-debug] GET    /swagger/*any             --> github.com/swaggo/gin-swagger.CustomWrapHandler.func1 (3 handlers)
[GIN-debug] GET    /api/v1/test              --> thor-backend/internal/controller.(*Server).ServeTest-fm (3 handlers)
[GIN-debug] GET    /debug/pprof/             --> github.com/gin-contrib/pprof.pprofHandler.func1 (3 handlers)
......
Listening port is 8080

Swagger doc

Directory

gin-web-example
├── Makefile        // 编译打包
├── README.md       // 使用说明
├── conf            // 配置文件
│   ├── config.dev.toml
│   ├── config.online.toml
│   └── config.pre.toml
├── docs            // 相关文档
├── internal    
│   ├── controller  // 控制入口
│   ├── dao         // 数据操作
│   ├── logger      // 日志加载
│   ├── logic       // 业务逻辑
│   ├── middleware  // 中间件层
│   ├── model       // 模型定义
│   └── setting     // 配置定义
├── main.go         // 程序入口
├── .air.conf       // 热重启配置
├── pkg             // 外部通用包
├── scripts         // 项目相关脚本
│   └── sql
└── vendor          // go mod依赖库

Features