gin-frame

command module
v0.0.0-...-96174dc Latest Latest
Warning

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

Go to latest
Published: May 27, 2025 License: MIT Imports: 1 Imported by: 0

README

gin-frame

Gin Project Template

本项目使用 gin 框架为核心搭建的一个脚手架,可以基于本项目快速完成业务开发,开箱📦 即用

# 执行迁移文件创建数据表
migrate -database 'mysql://root:root@tcp(127.0.0.1:3306)/go_layout?charset=utf8mb4&parseTime=True&loc=Local' -path data/migrations up

启动脚手架服务:

# 建议开启GO111MODULE
# go env -w GO111MODULE=on

# 下载依赖
go mod download

# 首次运行会自动复制一份示例配置(config/config.example.yaml)文件到config目录(config/config.yaml)
# 启动服务
go run main.go server

# 项目起来后执行下面命令访问示例路由
curl "http://127.0.0.1:9001/ping"
# {"message":"pong"}
curl "http://127.0.0.1:9001/api/v1/hello-world"
# {"code":0,"message":"OK","data":{"result":"hello gin-layout"},"cost":"6.151µs"}
curl "http://127.0.0.1:9001/api/v1/hello-world?name=world"
# {"code":0,"message":"OK","data":{"result":"hello world"},"cost":"6.87µs"}

更多用法使用以下命令查看:

go run main.go -h
部署
# 打包项目(如何打包其他os平台的包自行 google)
go build -o cmd/go_layout main.go

# 运行时请配置指定config文件的位置,否则可能会出现找不到配置的情况,修改完配置请重启
cmd/go-layout server -c="指定配置文件位置(/home/go-layout-config.yaml)"

# 使用 supervisord 管理进程配置示例如下
[program:go-layout]
command=/home/go-layout/go_layout -c=/home/go/go-layout/config.yaml
directory=/home/go/go-layout
autostart=true
startsecs=5
user=root
redirect_stderr=true
stdout_logfile=/home/go/go-layout/supervisord_go_layout.log

# nginx 反向代理配置示例
server {
    listen 80;
    server_name api.xxx.com;
    location / {
        proxy_set_header Host $host;
        proxy_pass http://172.0.0.1:9001;
    }
}
生产环境注意事项

在构建生产环境时,请配置好 .yaml 文件中基础路径 base_path,所有的日志记录文件会保存在该目录下的 {base_path}/logs/ 里面,该基础路径默认为执行命令的目录

其他说明
项目中使用到的包
代码贡献

不完善的地方,欢迎大家 Fork 并提交 PR!

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