Gin 构建的 web 项目
当前使用的版本 v1.43.0
brew install golangci-lint
brew upgrade golangci-lint
# binary will be $(go env GOPATH)/bin/golangci-lint
curl -sSfL https://github.com/raw/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.43.0
golangci-lint --version
golangci-lint run
pip install pre-commit
# 或者
curl https://pre-commit.com/install-local.py | python -
# 或者
brew install pre-commit
pre-commit --version
https://pre-commit.com/hooks.html 查询 golangci-lint hooks
pre-commit install
包 | 详情 |
---|---|
gin | Gin |
gorm V2 | ORM |
sql-migrate | 数据迁移 |
spf13/viper | 配置 |
spf13/cobra | CLI |
swaggo | Swagger |
casbin V2 | 权限配置 |
logrus | 日志包 |
go-file-rotatelogs | 日志文件分割 |
gin-contrib/sessions | Session包 |
go-redis V8 | 缓存 |
BigCache | 缓存 |
tableflip | 进程重启 |
ants | goroutine 池 |
热更新需要安装 air
展开查看
├── app 项目核心逻辑代码
│ ├── caches 缓存
│ ├── enums 枚举
│ ├── errno 错误码
│ ├── controllers 控制器
│ ├── models 模型
│ ├── middleware 中间件
│ ├── service 服务
│ ├── requests 参数校验
│ ├── responses 响应
│ └── helper.go 工具方法
│
├── console 控制台
│ ├── cmd cmd 文件
│ └── console.go cmd 加载
│
├── config 配置中心
│
├── database 数据库
│ └── migrations 数据迁移文件
│
├── pkg 项目依赖
│
├── doc 文档
│
├── public 项目公开静态文件(包含上传文件)
│ ├── css
│ ├── js
│ ├── js
│ ├── upload
│ └── assets
|
├── resources 项目资源
│ ├── assets assets
│ │ └── admin 后台前端项目
│ ├── static 打包静态文件
│ └── views 模板文件
│
├── routes 路由
│ ├── root.go 路由加载
│ ├── admin.go 后台 路由
│ ├── api.go api 路由
│ └── web.go web 路由
│
├── utils 工具
├── test 测试文件夹
├── storage 存放日志等文件
├── .air.toml 热更新配置
├── main.go 项目入口
├── config.yaml 动态项目配置
├── .drone.yml drone 配置
├── admin.sh 脚本
└── Makefile Makefile 文件
make
make install
make h
make enum name=TestType // 或者 test_type
make request name=/Api/TestRequest // 或者 test_request
make response name=/Api/testResponse // 或者 test_response
make model name=testModel // 或者 test_model
make cache name=testCache // 或者 test_cache
make controller name=admin/testController // 或者 admin/test_controller
make service name=test // 或者 admin/test
make migrate
make migrate:create name=create_tablename
make migrate:reset
make migrate:rollback
make migrate:refresh
make build [name=xxx]
make start name=xxx
make stop name=xxx
make pipeline name=xxx
展开查看
生成 win64位程序
make build:winamd64 [name=xxx]
生成 win32位程序
make build:win386 [name=xxx]
生成 darwin386 程序
make build:darwin386 [name=xxx]
生成 darwinamd64 程序
make build:darwinamd64 [name=xxx]
生成 darwinarm程序
make build:darwinarm [name=xxx]
生成 darwinarm64程序
make build:darwinarm64 [name=xxx]
生成 linux386程序
make build:linux386 [name=xxx]
生成 linuxamd64程序
make build:linuxamd64 [name=xxx]
生成 linuxarm程序
make build:linuxarm [name=xxx]
生成 linuxarm64程序
make build:linuxarm64 [name=xxx]
http://localhost:8080/swagger/index.html
make doc
make key:generate
make jwt-secret
make create-cmd name=?
make create-admin
make verifiers
session := sessions.Default(ctx)
if id := session.Get("user"); id == nil {
session.Set("user", 100)
// 将 sessionID 存入cookie
if err := session.Save(); err != nil {
log.Info(err)
}
}
提示 如果无法下载 golang.org/x 等包,可用 proxy 的方式下载包
export GOPROXY=https://goproxy.cn,direct
# 或者
go env -w GOPROXY=https://goproxy.cn,direct
-
gitlab + jenkins
-
gitea + drone
make web
make web:build
cd /resources/assets/admin
npm i
npm run dev
vim .env.production
npm run build:prod (打包生产环境配置)
// 打包的文件会生成在指定位置,无需更改
# 新建 env
cp .config.yml.example .config.yml
# 配置 env
vim .config.yml
# 运行
make
or
go run .
# 打包项目
make build name=main
or
go build .
tableflip 仅适用于 Linux 和 macOS。 运行程序后,会在根目录下生成 pid 文件。
配合 make pipeline name={name}
命令,实现 零停机 平滑重启 。
[Unit]
Description=Service
[Service]
ExecStart=/path/to/binary -some-flag /path/to/pid-file
ExecReload=/bin/kill -HUP $MAINPID
PIDFile=/path/to/pid-file
示例
# /etc/systemd/system/app.service
[Unit]
Description=Service
[Service]
ExecStart=/work_path/main
ExecReload=/bin/kill -HUP $MAINPID
PIDFile=/work_path/app.pid