gin+vue进行极速开发的全栈后台管理系统
Github地址 git clone https://github.com/flipped-aurora/gin-vue-admin.git
中文文档 https://www.gin-vue-admin.com/docs/
前端打包
编译web端 cnpm install
测试用cnpm run serve
打包使用cnpm run build
server文件夹下config.yaml
配置里面mysql数据表,然后执行initdb
linux下操作初始化
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.io,direct
make gva # 在server项目下,先构建gva终端工具
make initdb # 使用gva进行初始化数据, 如果不使用make initdb, 使用./gva initdb也是可以的
后端编译
编译go进入server 先使用 go mod init
,go mod tidy
,go build -o s.exe main.go
前端打包到go
打包前端到go文件中,在文件serve/core/server.go
里面添加Router.Static("/admin", "./resource/dist")
放到线上
然后在生成的ginvueadmin.exe,resource/dist,config.yaml
三个同一级别
前端文件.env.production
中VUE_APP_BASE_API = '/api'
是线上,.env.development
中VUE_APP_BASE_API = '/api'
是开发版,vue.config.js
中
target:`http://h5.api.shanliwawa.top/api`,//线上绑定域名用
target: `http://127.0.0.1:8888/`,//测试本地用
nginx配置
代理静态文件 复制生成的dist文件夹到nginx,配置如下
index index.html index.htm;
root C:/www/h5/dist;
配置代理go服务,这里两个都可以登录其中http://h5.api.shanliwawa.top/
是nginx代理,访问的是nginx dist目录文件,另一个是http://h5.api.shanliwawa.top/api/admin/
访问的是go代理的静态文件,两种都是使用了nginx反向代理
location ~ ^/api/ {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
rewrite ^/api/(.*)$ /$1 break;
proxy_pass http://127.0.0.1:8888;
}
location /api/swagger/index.html {
proxy_pass http://127.0.0.1:8888/swagger/index.html;
}
常见问题
- 禁止访问官方网站,在package.json中serve:
node openDocument.js &&
去掉,就不会访问了 - go.mod文件中
github.com/casbin/gorm-adapter/v3 v3.0.2
如果版本是3.0.4会导致出错,所以记得修改版本. - swag 小于1.67
github.com/swaggo/swag v1.6.7
大于此版本会出现swag init
不能用swag
windows下执行swag.exe init ,linux下执行swag init,执行完成之后会生成docs目录,里面含有自动生成的文档控制台
gin-vue-admin\server\initialize\router.go这几行功能gin.SetMode(gin.ReleaseMode)//正式版启用 //gin.SetMode(gin.DebugMode)//debug使用 gin.DisableConsoleColor()//控制台禁用输出