diff --git a/.gitignore b/.gitignore index 22e09bae..70797504 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ temp/ !temp vendor config/settings.dev.yml +go-admin diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..95290124 --- /dev/null +++ b/Makefile @@ -0,0 +1,14 @@ +PROJECT:=go-admin + +.PHONY: build +build: + CGO_ENABLED=0 go build -o go-admin main.go +build-sqlite: + go build -tags sqlite3 -o go-admin main.go +#.PHONY: test +#test: +# go test -v ./... -cover + +#.PHONY: docker +#docker: +# docker build . -t go-admin:latest diff --git a/README.md b/README.md index b8a6ff8c..d2ed8cd6 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@

- [English](./README.en.md) | 简体中文 + [English](https://github.com/wenjianzhang/go-admin/blob/master/README.en.md) | 简体中文 ##### 基于Gin + Vue + Element UI的前后端分离权限管理系统 @@ -45,6 +45,8 @@ - 表单构建工具 +- 多命令模式 + - TODO: 单元测试 @@ -71,29 +73,26 @@ settings: application: # 项目启动环境 - env: dev - # 当 env:demo 时,GET以外的请求操作提示 - envmsg: "谢谢您的参与,但为了大家更好的体验,所以本次提交就算了吧!" - # 主机ip 或者域名,默认0.0.0.0 - host: 0.0.0.0 - # 是否需要初始化数据库结构以及基本数据;true:需要;false:不需要 - isinit: false - # log存放路径 - logpath: temp/logs/log.log + mode: dev # dev开发环境 test测试环境 prod线上环境;当 mode:demo 时,GET以外的请求操作提示 + demomsg: "谢谢您的参与,但为了大家更好的体验,所以本次提交就算了吧!" + host: 0.0.0.0 # 主机ip 或者域名,默认0.0.0.0 # 服务名称 name: go-admin # 服务端口 port: 8000 readtimeout: 1 writertimeout: 2 + log: + # 日志文件存放路径 + dir: temp/logs jwt: # JWT加密字符串 - jwtsecret: go-admin + secret: go-admin # 过期时间单位:秒 timeout: 3600 database: # 数据库名称 - database: dbname + name: dbname # 数据库类型 dbtype: mysql # 数据库地址 @@ -111,7 +110,7 @@ settings: ## 📦 本地开发 -首次启动说明 +### 首次启动说明 ```bash # 获取代码 @@ -128,29 +127,32 @@ vi ./config/setting.yml (更改isinit和数据库连接) # 1. 配置文件中修改数据库信息 # 注意: settings.database 下对应的配置数据) -# 2. 确认数据库初始化参数 -# 注意: settings.application.isinit 如果是首次启动,请把当前值设置成true,系统会自动初始化数据库结构以及基本的数据信息; -# 3. 确认log路径 +# 2. 确认log路径 + +``` + +### 初始化数据库,以及服务启动 +``` +# 首次配置需要初始化数据库资源信息 +./go-admin migrate -c config/settings.yml -m dev # 启动项目,也可以用IDE进行调试 -./go-admin +./go-admin server -c config/settings.yml -p 8000 -m dev ``` [在线文档](https://wenjianzhang.github.io/go-admin-site) -文档生成 +### 文档生成 ```bash swag init -``` -如果没有swag命令 go get安装一下即可 -```bash +# 如果没有swag命令 go get安装一下即可 go get -u github.com/swaggo/swag/cmd/swag ``` -交叉编译 +### 交叉编译 ```bash env GOOS=windows GOARCH=amd64 go build main.go @@ -167,6 +169,15 @@ env GOOS=linux GOARCH=amd64 go build main.go ## 📈 版本 +### 2020-04-23 新功能及优化 + +1. 添加单服务命令 +2. 添加单数据库数据化命令 +3. 调整项目结构 +3. 部分代码优化 +3. 添加根接口 +4. 其他已知bug的修复 + ### 2020-04-13 新功能及优化 1. 数据库初始化方式改为gorm 迁移方式 @@ -212,7 +223,7 @@ env GOOS=linux GOARCH=amd64 go build main.go 微信 - go-admin技术交流甲号已满 + 此群已满 go-admin技术交流乙号 diff --git a/apis/log/loginLog.go b/apis/log/loginLog.go index a8d4446e..891b0810 100644 --- a/apis/log/loginLog.go +++ b/apis/log/loginLog.go @@ -4,9 +4,8 @@ import ( "github.com/gin-gonic/gin" "github.com/gin-gonic/gin/binding" "go-admin/models" - "go-admin/pkg" - "go-admin/pkg/app" - "go-admin/pkg/utils" + "go-admin/tools" + "go-admin/tools/app" "net/http" ) @@ -18,7 +17,7 @@ import ( // @Param dictType query string false "dictType" // @Param pageSize query int false "页条数" // @Param pageIndex query int false "页码" -// @Success 200 {object} models.Response "{"code": 200, "data": [...]}" +// @Success 200 {object} app.Response "{"code": 200, "data": [...]}" // @Router /api/v1/loginloglist [get] // @Security func GetLoginLogList(c *gin.Context) { @@ -29,19 +28,19 @@ func GetLoginLogList(c *gin.Context) { size := c.Request.FormValue("pageSize") if size != "" { - pageSize = pkg.StrToInt(err, size) + pageSize = tools.StrToInt(err, size) } index := c.Request.FormValue("pageIndex") if index != "" { - pageIndex = pkg.StrToInt(err, index) + pageIndex = tools.StrToInt(err, index) } data.Username = c.Request.FormValue("username") data.Status = c.Request.FormValue("status") data.Ipaddr = c.Request.FormValue("ipaddr") result, count, err := data.GetPage(pageSize, pageIndex) - pkg.HasError(err, "", -1) + tools.HasError(err, "", -1) var mp = make(map[string]interface{}, 3) mp["list"] = result @@ -58,14 +57,14 @@ func GetLoginLogList(c *gin.Context) { // @Description 获取JSON // @Tags 登录日志 // @Param infoId path int true "infoId" -// @Success 200 {object} models.Response "{"code": 200, "data": [...]}" +// @Success 200 {object} app.Response "{"code": 200, "data": [...]}" // @Router /api/v1/loginlog/{infoId} [get] // @Security func GetLoginLog(c *gin.Context) { var LoginLog models.LoginLog - LoginLog.InfoId, _ = utils.StringToInt(c.Param("infoId")) + LoginLog.InfoId, _ = tools.StringToInt(c.Param("infoId")) result, err := LoginLog.Get() - pkg.HasError(err, "抱歉未找到相关信息", -1) + tools.HasError(err, "抱歉未找到相关信息", -1) var res app.Response res.Data = result @@ -85,9 +84,9 @@ func GetLoginLog(c *gin.Context) { func InsertLoginLog(c *gin.Context) { var data models.LoginLog err := c.BindWith(&data, binding.JSON) - pkg.HasError(err, "", 500) + tools.HasError(err, "", 500) result, err := data.Create() - pkg.HasError(err, "", -1) + tools.HasError(err, "", -1) var res app.Response res.Data = result c.JSON(http.StatusOK, res.ReturnOK()) @@ -106,9 +105,9 @@ func InsertLoginLog(c *gin.Context) { func UpdateLoginLog(c *gin.Context) { var data models.LoginLog err := c.BindWith(&data, binding.JSON) - pkg.HasError(err, "", -1) + tools.HasError(err, "", -1) result, err := data.Update(data.InfoId) - pkg.HasError(err, "", -1) + tools.HasError(err, "", -1) var res app.Response res.Data = result c.JSON(http.StatusOK, res.ReturnOK()) @@ -123,10 +122,10 @@ func UpdateLoginLog(c *gin.Context) { // @Router /api/v1/loginlog/{infoId} [delete] func DeleteLoginLog(c *gin.Context) { var data models.LoginLog - data.UpdateBy = utils.GetUserIdStr(c) - IDS := utils.IdsStrToIdsIntGroup("infoId", c) + data.UpdateBy = tools.GetUserIdStr(c) + IDS := tools.IdsStrToIdsIntGroup("infoId", c) _, err := data.BatchDelete(IDS) - pkg.HasError(err, "修改失败", 500) + tools.HasError(err, "修改失败", 500) var res app.Response res.Msg = "删除成功" c.JSON(http.StatusOK, res.ReturnOK()) diff --git a/apis/log/operlog.go b/apis/log/operlog.go index 052df5e0..b2e1c3fe 100644 --- a/apis/log/operlog.go +++ b/apis/log/operlog.go @@ -4,9 +4,8 @@ import ( "github.com/gin-gonic/gin" "github.com/gin-gonic/gin/binding" "go-admin/models" - "go-admin/pkg" - "go-admin/pkg/app" - "go-admin/pkg/utils" + "go-admin/tools" + "go-admin/tools/app" "net/http" ) @@ -18,7 +17,7 @@ import ( // @Param dictType query string false "dictType" // @Param pageSize query int false "页条数" // @Param pageIndex query int false "页码" -// @Success 200 {object} models.Response "{"code": 200, "data": [...]}" +// @Success 200 {object} app.Response "{"code": 200, "data": [...]}" // @Router /api/v1/operloglist [get] // @Security func GetOperLogList(c *gin.Context) { @@ -29,19 +28,19 @@ func GetOperLogList(c *gin.Context) { size := c.Request.FormValue("pageSize") if size != "" { - pageSize = pkg.StrToInt(err, size) + pageSize = tools.StrToInt(err, size) } index := c.Request.FormValue("pageIndex") if index != "" { - pageIndex = pkg.StrToInt(err, index) + pageIndex = tools.StrToInt(err, index) } data.OperName = c.Request.FormValue("operName") data.Status = c.Request.FormValue("status") data.OperIp = c.Request.FormValue("operIp") result, count, err := data.GetPage(pageSize, pageIndex) - pkg.HasError(err, "", -1) + tools.HasError(err, "", -1) var mp = make(map[string]interface{}, 3) mp["list"] = result @@ -59,14 +58,14 @@ func GetOperLogList(c *gin.Context) { // @Description 获取JSON // @Tags 登录日志 // @Param infoId path int true "infoId" -// @Success 200 {object} models.Response "{"code": 200, "data": [...]}" +// @Success 200 {object} app.Response "{"code": 200, "data": [...]}" // @Router /api/v1/operlog/{infoId} [get] // @Security func GetOperLog(c *gin.Context) { var OperLog models.SysOperLog - OperLog.OperId, _ = utils.StringToInt(c.Param("operId")) + OperLog.OperId, _ = tools.StringToInt(c.Param("operId")) result, err := OperLog.Get() - pkg.HasError(err, "抱歉未找到相关信息", -1) + tools.HasError(err, "抱歉未找到相关信息", -1) var res app.Response res.Data = result c.JSON(http.StatusOK, res.ReturnOK()) @@ -85,9 +84,9 @@ func GetOperLog(c *gin.Context) { func InsertOperLog(c *gin.Context) { var data models.SysOperLog err := c.BindWith(&data, binding.JSON) - pkg.HasError(err, "", 500) + tools.HasError(err, "", 500) result, err := data.Create() - pkg.HasError(err, "", -1) + tools.HasError(err, "", -1) var res app.Response res.Data = result c.JSON(http.StatusOK, res.ReturnOK()) @@ -102,10 +101,10 @@ func InsertOperLog(c *gin.Context) { // @Router /api/v1/operlog/{operId} [delete] func DeleteOperLog(c *gin.Context) { var data models.SysOperLog - data.UpdateBy = utils.GetUserIdStr(c) - IDS := utils.IdsStrToIdsIntGroup("operId", c) + data.UpdateBy = tools.GetUserIdStr(c) + IDS := tools.IdsStrToIdsIntGroup("operId", c) _, err := data.BatchDelete(IDS) - pkg.HasError(err, "删除失败", 500) + tools.HasError(err, "删除失败", 500) var res app.Response res.Msg = "删除成功" c.JSON(http.StatusOK, res.ReturnOK()) diff --git a/apis/monitor/server.go b/apis/monitor/server.go index d54d9d14..778498f5 100644 --- a/apis/monitor/server.go +++ b/apis/monitor/server.go @@ -5,7 +5,7 @@ import ( "github.com/shirou/gopsutil/cpu" "github.com/shirou/gopsutil/disk" "github.com/shirou/gopsutil/mem" - "go-admin/pkg/app" + "go-admin/tools/app" "runtime" ) diff --git a/apis/system/captcha.go b/apis/system/captcha.go index dc5364b9..9c2d3fe0 100644 --- a/apis/system/captcha.go +++ b/apis/system/captcha.go @@ -2,14 +2,14 @@ package system import ( "github.com/gin-gonic/gin" - "go-admin/pkg" - "go-admin/pkg/app" - "go-admin/pkg/captcha" + "go-admin/tools" + "go-admin/tools/app" + "go-admin/tools/captcha" ) func GenerateCaptchaHandler(c *gin.Context) { id, b64s, err := captcha.DriverDigitFunc() - pkg.HasError(err, "验证码获取失败", 500) + tools.HasError(err, "验证码获取失败", 500) app.Custum(c, gin.H{ "code": 200, "data": b64s, diff --git a/apis/system/config.go b/apis/system/config.go index f7e69cb0..c74b900b 100644 --- a/apis/system/config.go +++ b/apis/system/config.go @@ -4,10 +4,9 @@ import ( "github.com/gin-gonic/gin" "github.com/gin-gonic/gin/binding" "go-admin/models" - "go-admin/pkg" - "go-admin/pkg/app" - "go-admin/pkg/app/msg" - "go-admin/pkg/utils" + "go-admin/tools" + "go-admin/tools/app" + "go-admin/tools/app/msg" "net/http" ) @@ -19,7 +18,7 @@ import ( // @Param configType query string false "configType" // @Param pageSize query int false "页条数" // @Param pageIndex query int false "页码" -// @Success 200 {object} models.Response "{"code": 200, "data": [...]}" +// @Success 200 {object} app.Response "{"code": 200, "data": [...]}" // @Router /api/v1/configList [get] // @Security func GetConfigList(c *gin.Context) { @@ -29,19 +28,19 @@ func GetConfigList(c *gin.Context) { var pageIndex = 1 if size := c.Request.FormValue("pageSize"); size != "" { - pageSize = pkg.StrToInt(err, size) + pageSize = tools.StrToInt(err, size) } if index := c.Request.FormValue("pageIndex"); index != "" { - pageIndex = pkg.StrToInt(err, index) + pageIndex = tools.StrToInt(err, index) } data.ConfigKey = c.Request.FormValue("configKey") data.ConfigName = c.Request.FormValue("configName") data.ConfigType = c.Request.FormValue("configType") - data.DataScope = utils.GetUserIdStr(c) + data.DataScope = tools.GetUserIdStr(c) result, count, err := data.GetPage(pageSize, pageIndex) - pkg.HasError(err, "", -1) + tools.HasError(err, "", -1) var mp = make(map[string]interface{}, 3) mp["list"] = result @@ -59,14 +58,14 @@ func GetConfigList(c *gin.Context) { // @Description 获取JSON // @Tags 配置 // @Param configId path int true "配置编码" -// @Success 200 {object} models.Response "{"code": 200, "data": [...]}" +// @Success 200 {object} app.Response "{"code": 200, "data": [...]}" // @Router /api/v1/config/{configId} [get] // @Security func GetConfig(c *gin.Context) { var Config models.SysConfig - Config.ConfigId, _ = utils.StringToInt(c.Param("configId")) + Config.ConfigId, _ = tools.StringToInt(c.Param("configId")) result, err := Config.Get() - pkg.HasError(err, "抱歉未找到相关信息", -1) + tools.HasError(err, "抱歉未找到相关信息", -1) var res app.Response res.Data = result @@ -78,14 +77,14 @@ func GetConfig(c *gin.Context) { // @Description 获取JSON // @Tags 配置 // @Param configKey path int true "configKey" -// @Success 200 {object} models.Response "{"code": 200, "data": [...]}" +// @Success 200 {object} app.Response "{"code": 200, "data": [...]}" // @Router /api/v1/configKey/{configKey} [get] // @Security func GetConfigByConfigKey(c *gin.Context) { var Config models.SysConfig Config.ConfigKey = c.Param("configKey") result, err := Config.Get() - pkg.HasError(err, "抱歉未找到相关信息", -1) + tools.HasError(err, "抱歉未找到相关信息", -1) app.OK(c, result,result.ConfigValue) } @@ -103,10 +102,10 @@ func GetConfigByConfigKey(c *gin.Context) { func InsertConfig(c *gin.Context) { var data models.SysConfig err := c.BindWith(&data, binding.JSON) - data.CreateBy = utils.GetUserIdStr(c) - pkg.HasError(err, "", 500) + data.CreateBy = tools.GetUserIdStr(c) + tools.HasError(err, "", 500) result, err := data.Create() - pkg.HasError(err, "", -1) + tools.HasError(err, "", -1) app.OK(c, result,"") } @@ -116,7 +115,7 @@ func InsertConfig(c *gin.Context) { // @Tags 配置 // @Accept application/json // @Product application/json -// @Param data body models.Config true "body" +// @Param data body models.SysConfig true "body" // @Success 200 {string} string "{"code": 200, "message": "添加成功"}" // @Success 200 {string} string "{"code": -1, "message": "添加失败"}" // @Router /api/v1/config [put] @@ -124,10 +123,10 @@ func InsertConfig(c *gin.Context) { func UpdateConfig(c *gin.Context) { var data models.SysConfig err := c.BindWith(&data, binding.JSON) - pkg.HasError(err, "数据解析失败", -1) - data.UpdateBy = utils.GetUserIdStr(c) + tools.HasError(err, "数据解析失败", -1) + data.UpdateBy = tools.GetUserIdStr(c) result, err := data.Update(data.ConfigId) - pkg.HasError(err, "", -1) + tools.HasError(err, "", -1) app.OK(c, result,"") } @@ -140,10 +139,10 @@ func UpdateConfig(c *gin.Context) { // @Router /api/v1/config/{configId} [delete] func DeleteConfig(c *gin.Context) { var data models.SysConfig - id, err := utils.StringToInt(c.Param("configId")) - data.UpdateBy = utils.GetUserIdStr(c) + id, err := tools.StringToInt(c.Param("configId")) + data.UpdateBy = tools.GetUserIdStr(c) data.ConfigId = id _, err = data.Delete() - pkg.HasError(err, "修改失败", 500) - app.OK(c, nil,msg.DeletedSuccess) + tools.HasError(err, "修改失败", 500) + app.OK(c, nil, msg.DeletedSuccess) } diff --git a/apis/system/dept.go b/apis/system/dept.go index a123f5cd..14fdd630 100644 --- a/apis/system/dept.go +++ b/apis/system/dept.go @@ -4,10 +4,9 @@ import ( "github.com/gin-gonic/gin" "github.com/gin-gonic/gin/binding" "go-admin/models" - "go-admin/pkg" - "go-admin/pkg/app" - "go-admin/pkg/app/msg" - "go-admin/pkg/utils" + "go-admin/tools" + "go-admin/tools/app" + "go-admin/tools/app/msg" ) // @Summary 分页部门列表数据 @@ -16,17 +15,17 @@ import ( // @Param name query string false "name" // @Param id query string false "id" // @Param position query string false "position" -// @Success 200 {object} models.Response "{"code": 200, "data": [...]}" +// @Success 200 {object} app.Response "{"code": 200, "data": [...]}" // @Router /api/v1/deptList [get] // @Security func GetDeptList(c *gin.Context) { var Dept models.Dept Dept.DeptName = c.Request.FormValue("deptName") Dept.Status = c.Request.FormValue("status") - Dept.DeptId, _ = utils.StringToInt(c.Request.FormValue("deptId")) - Dept.DataScope = utils.GetUserIdStr(c) + Dept.DeptId, _ = tools.StringToInt(c.Request.FormValue("deptId")) + Dept.DataScope = tools.GetUserIdStr(c) result, err := Dept.SetDept(true) - pkg.HasError(err, "抱歉未找到相关信息", -1) + tools.HasError(err, "抱歉未找到相关信息", -1) app.OK(c,result,"") } @@ -34,9 +33,9 @@ func GetDeptTree(c *gin.Context) { var Dept models.Dept Dept.DeptName = c.Request.FormValue("deptName") Dept.Status= c.Request.FormValue("status") - Dept.DeptId, _ = utils.StringToInt(c.Request.FormValue("deptId")) + Dept.DeptId, _ = tools.StringToInt(c.Request.FormValue("deptId")) result, err := Dept.SetDept(false) - pkg.HasError(err, "抱歉未找到相关信息", -1) + tools.HasError(err, "抱歉未找到相关信息", -1) app.OK(c,result,"") } @@ -45,16 +44,16 @@ func GetDeptTree(c *gin.Context) { // @Tags 部门 // @Param deptId path string false "deptId" // @Param position query string false "position" -// @Success 200 {object} models.Response "{"code": 200, "data": [...]}" +// @Success 200 {object} app.Response "{"code": 200, "data": [...]}" // @Router /api/v1/dept/{deptId} [get] // @Security func GetDept(c *gin.Context) { var Dept models.Dept - Dept.DeptId, _ = utils.StringToInt(c.Param("deptId")) - Dept.DataScope = utils.GetUserIdStr(c) + Dept.DeptId, _ = tools.StringToInt(c.Param("deptId")) + Dept.DataScope = tools.GetUserIdStr(c) result, err := Dept.Get() - pkg.HasError(err, msg.NotFound, 404) - app.OK(c,result,msg.GetSuccess) + tools.HasError(err, msg.NotFound, 404) + app.OK(c,result, msg.GetSuccess) } // @Summary 添加部门 @@ -70,11 +69,11 @@ func GetDept(c *gin.Context) { func InsertDept(c *gin.Context) { var data models.Dept err := c.BindWith(&data, binding.JSON) - pkg.HasError(err, "", 500) - data.CreateBy = utils.GetUserIdStr(c) + tools.HasError(err, "", 500) + data.CreateBy = tools.GetUserIdStr(c) result, err := data.Create() - pkg.HasError(err, "", -1) - app.OK(c,result,msg.CreatedSuccess) + tools.HasError(err, "", -1) + app.OK(c,result, msg.CreatedSuccess) } // @Summary 修改部门 @@ -91,11 +90,11 @@ func InsertDept(c *gin.Context) { func UpdateDept(c *gin.Context) { var data models.Dept err := c.BindWith(&data, binding.JSON) - pkg.HasError(err, "", -1) - data.UpdateBy = utils.GetUserIdStr(c) + tools.HasError(err, "", -1) + data.UpdateBy = tools.GetUserIdStr(c) result, err := data.Update(data.DeptId) - pkg.HasError(err, "", -1) - app.OK(c,result,msg.UpdatedSuccess) + tools.HasError(err, "", -1) + app.OK(c,result, msg.UpdatedSuccess) } // @Summary 删除部门 @@ -107,23 +106,23 @@ func UpdateDept(c *gin.Context) { // @Router /api/v1/dept/{id} [delete] func DeleteDept(c *gin.Context) { var data models.Dept - id, err := utils.StringToInt(c.Param("id")) + id, err := tools.StringToInt(c.Param("id")) _, err = data.Delete(id) - pkg.HasError(err, "删除失败", 500) - app.OK(c,"",msg.DeletedSuccess) + tools.HasError(err, "删除失败", 500) + app.OK(c,"", msg.DeletedSuccess) } func GetDeptTreeRoleselect(c *gin.Context) { var Dept models.Dept var SysRole models.SysRole - id, err := utils.StringToInt(c.Param("roleId")) + id, err := tools.StringToInt(c.Param("roleId")) SysRole.RoleId = id result, err := Dept.SetDeptLable() - pkg.HasError(err, msg.NotFound, -1) + tools.HasError(err, msg.NotFound, -1) menuIds := make([]int, 0) if id != 0 { menuIds, err = SysRole.GetRoleDeptId() - pkg.HasError(err, "抱歉未找到相关信息", -1) + tools.HasError(err, "抱歉未找到相关信息", -1) } app.Custum(c,gin.H{ "code": 200, diff --git a/apis/system/dict/dictData.go b/apis/system/dict/dictData.go index f5d94b3f..00a29cab 100644 --- a/apis/system/dict/dictData.go +++ b/apis/system/dict/dictData.go @@ -4,9 +4,8 @@ import ( "github.com/gin-gonic/gin" "github.com/gin-gonic/gin/binding" "go-admin/models" - "go-admin/pkg" - "go-admin/pkg/app" - "go-admin/pkg/utils" + "go-admin/tools" + "go-admin/tools/app" "net/http" ) @@ -18,7 +17,7 @@ import ( // @Param dictType query string false "dictType" // @Param pageSize query int false "页条数" // @Param pageIndex query int false "页码" -// @Success 200 {object} models.Response "{"code": 200, "data": [...]}" +// @Success 200 {object} app.Response "{"code": 200, "data": [...]}" // @Router /api/v1/dict/data/list [get] // @Security func GetDictDataList(c *gin.Context) { @@ -28,21 +27,21 @@ func GetDictDataList(c *gin.Context) { var pageIndex = 1 if size := c.Request.FormValue("pageSize"); size != "" { - pageSize = pkg.StrToInt(err, size) + pageSize = tools.StrToInt(err, size) } if index := c.Request.FormValue("pageIndex"); index != "" { - pageIndex = pkg.StrToInt(err, index) + pageIndex = tools.StrToInt(err, index) } data.DictLabel = c.Request.FormValue("dictLabel") data.Status = c.Request.FormValue("status") data.DictType = c.Request.FormValue("dictType") id := c.Request.FormValue("dictCode") - data.DictCode, _ = utils.StringToInt(id) - data.DataScope = utils.GetUserIdStr(c) + data.DictCode, _ = tools.StringToInt(id) + data.DataScope = tools.GetUserIdStr(c) result, count, err := data.GetPage(pageSize, pageIndex) - pkg.HasError(err, "", -1) + tools.HasError(err, "", -1) var mp = make(map[string]interface{}, 3) mp["list"] = result @@ -60,15 +59,15 @@ func GetDictDataList(c *gin.Context) { // @Description 获取JSON // @Tags 字典数据 // @Param dictCode path int true "字典编码" -// @Success 200 {object} models.Response "{"code": 200, "data": [...]}" +// @Success 200 {object} app.Response "{"code": 200, "data": [...]}" // @Router /api/v1/dict/data/{dictCode} [get] // @Security func GetDictData(c *gin.Context) { var DictData models.DictData DictData.DictLabel = c.Request.FormValue("dictLabel") - DictData.DictCode, _ = utils.StringToInt(c.Param("dictCode")) + DictData.DictCode, _ = tools.StringToInt(c.Param("dictCode")) result, err := DictData.GetByCode() - pkg.HasError(err, "抱歉未找到相关信息", -1) + tools.HasError(err, "抱歉未找到相关信息", -1) var res app.Response res.Data = result c.JSON(http.StatusOK, res.ReturnOK()) @@ -78,14 +77,14 @@ func GetDictData(c *gin.Context) { // @Description 获取JSON // @Tags 字典数据 // @Param dictType path int true "dictType" -// @Success 200 {object} models.Response "{"code": 200, "data": [...]}" +// @Success 200 {object} app.Response "{"code": 200, "data": [...]}" // @Router /api/v1/dict/databyType/{dictType} [get] // @Security func GetDictDataByDictType(c *gin.Context) { var DictData models.DictData DictData.DictType = c.Param("dictType") result, err := DictData.Get() - pkg.HasError(err, "抱歉未找到相关信息", -1) + tools.HasError(err, "抱歉未找到相关信息", -1) var res app.Response res.Data = result @@ -105,10 +104,10 @@ func GetDictDataByDictType(c *gin.Context) { func InsertDictData(c *gin.Context) { var data models.DictData err := c.BindWith(&data, binding.JSON) - data.CreateBy = utils.GetUserIdStr(c) - pkg.HasError(err, "", 500) + data.CreateBy = tools.GetUserIdStr(c) + tools.HasError(err, "", 500) result, err := data.Create() - pkg.HasError(err, "", -1) + tools.HasError(err, "", -1) var res app.Response res.Data = result c.JSON(http.StatusOK, res.ReturnOK()) @@ -127,10 +126,10 @@ func InsertDictData(c *gin.Context) { func UpdateDictData(c *gin.Context) { var data models.DictData err := c.BindWith(&data, binding.JSON) - data.UpdateBy = utils.GetUserIdStr(c) - pkg.HasError(err, "", -1) + data.UpdateBy = tools.GetUserIdStr(c) + tools.HasError(err, "", -1) result, err := data.Update(data.DictCode) - pkg.HasError(err, "", -1) + tools.HasError(err, "", -1) var res app.Response res.Data = result c.JSON(http.StatusOK, res.ReturnOK()) @@ -145,10 +144,10 @@ func UpdateDictData(c *gin.Context) { // @Router /api/v1/dict/data/{dictCode} [delete] func DeleteDictData(c *gin.Context) { var data models.DictData - id, err := utils.StringToInt(c.Param("dictCode")) - data.UpdateBy = utils.GetUserIdStr(c) + id, err := tools.StringToInt(c.Param("dictCode")) + data.UpdateBy = tools.GetUserIdStr(c) _, err = data.Delete(id) - pkg.HasError(err, "修改失败", 500) + tools.HasError(err, "修改失败", 500) var res app.Response res.Msg = "删除成功" diff --git a/apis/system/dict/dictType.go b/apis/system/dict/dictType.go index 9e7744b1..c7d2b193 100644 --- a/apis/system/dict/dictType.go +++ b/apis/system/dict/dictType.go @@ -4,9 +4,8 @@ import ( "github.com/gin-gonic/gin" "github.com/gin-gonic/gin/binding" "go-admin/models" - "go-admin/pkg" - "go-admin/pkg/app" - "go-admin/pkg/utils" + "go-admin/tools" + "go-admin/tools/app" "net/http" ) @@ -18,7 +17,7 @@ import ( // @Param dictType query string false "dictType" // @Param pageSize query int false "页条数" // @Param pageIndex query int false "页码" -// @Success 200 {object} models.Response "{"code": 200, "data": [...]}" +// @Success 200 {object} app.Response "{"code": 200, "data": [...]}" // @Router /api/v1/dict/type/list [get] // @Security func GetDictTypeList(c *gin.Context) { @@ -28,20 +27,20 @@ func GetDictTypeList(c *gin.Context) { var pageIndex = 1 if size := c.Request.FormValue("pageSize"); size != "" { - pageSize = pkg.StrToInt(err, size) + pageSize = tools.StrToInt(err, size) } if index := c.Request.FormValue("pageIndex"); index != "" { - pageIndex = pkg.StrToInt(err, index) + pageIndex = tools.StrToInt(err, index) } data.DictName = c.Request.FormValue("dictName") id := c.Request.FormValue("dictId") - data.DictId, _ = utils.StringToInt(id) + data.DictId, _ = tools.StringToInt(id) data.DictType = c.Request.FormValue("dictType") - data.DataScope = utils.GetUserIdStr(c) + data.DataScope = tools.GetUserIdStr(c) result, count, err := data.GetPage(pageSize, pageIndex) - pkg.HasError(err, "", -1) + tools.HasError(err, "", -1) var mp = make(map[string]interface{}, 3) mp["list"] = result @@ -58,15 +57,15 @@ func GetDictTypeList(c *gin.Context) { // @Description 获取JSON // @Tags 字典类型 // @Param dictId path int true "字典类型编码" -// @Success 200 {object} models.Response "{"code": 200, "data": [...]}" +// @Success 200 {object} app.Response "{"code": 200, "data": [...]}" // @Router /api/v1/dict/type/{dictId} [get] // @Security func GetDictType(c *gin.Context) { var DictType models.DictType DictType.DictName = c.Request.FormValue("dictName") - DictType.DictId, _ = utils.StringToInt(c.Param("dictId")) + DictType.DictId, _ = tools.StringToInt(c.Param("dictId")) result, err := DictType.Get() - pkg.HasError(err, "抱歉未找到相关信息", -1) + tools.HasError(err, "抱歉未找到相关信息", -1) var res app.Response res.Data = result c.JSON(http.StatusOK, res.ReturnOK()) @@ -76,9 +75,9 @@ func GetDictType(c *gin.Context) { func GetDictTypeOptionSelect(c *gin.Context) { var DictType models.DictType DictType.DictName = c.Request.FormValue("dictName") - DictType.DictId, _ = utils.StringToInt(c.Param("dictId")) + DictType.DictId, _ = tools.StringToInt(c.Param("dictId")) result, err := DictType.GetList() - pkg.HasError(err, "抱歉未找到相关信息", -1) + tools.HasError(err, "抱歉未找到相关信息", -1) var res app.Response res.Data = result c.JSON(http.StatusOK, res.ReturnOK()) @@ -97,10 +96,10 @@ func GetDictTypeOptionSelect(c *gin.Context) { func InsertDictType(c *gin.Context) { var data models.DictType err := c.BindWith(&data, binding.JSON) - data.CreateBy = utils.GetUserIdStr(c) - pkg.HasError(err, "", 500) + data.CreateBy = tools.GetUserIdStr(c) + tools.HasError(err, "", 500) result, err := data.Create() - pkg.HasError(err, "", -1) + tools.HasError(err, "", -1) var res app.Response res.Data = result c.JSON(http.StatusOK, res.ReturnOK()) @@ -119,10 +118,10 @@ func InsertDictType(c *gin.Context) { func UpdateDictType(c *gin.Context) { var data models.DictType err := c.BindWith(&data, binding.JSON) - data.UpdateBy = utils.GetUserIdStr(c) - pkg.HasError(err, "", -1) + data.UpdateBy = tools.GetUserIdStr(c) + tools.HasError(err, "", -1) result, err := data.Update(data.DictId) - pkg.HasError(err, "", -1) + tools.HasError(err, "", -1) var res app.Response res.Data = result c.JSON(http.StatusOK, res.ReturnOK()) @@ -137,10 +136,10 @@ func UpdateDictType(c *gin.Context) { // @Router /api/v1/dict/type/{dictId} [delete] func DeleteDictType(c *gin.Context) { var data models.DictType - id, err := utils.StringToInt(c.Param("dictId")) - data.UpdateBy = utils.GetUserIdStr(c) + id, err := tools.StringToInt(c.Param("dictId")) + data.UpdateBy = tools.GetUserIdStr(c) _, err = data.Delete(id) - pkg.HasError(err, "修改失败", 500) + tools.HasError(err, "修改失败", 500) c.JSON(http.StatusOK, gin.H{ "code": 200, diff --git a/apis/system/index.go b/apis/system/index.go new file mode 100644 index 00000000..87d3b3ea --- /dev/null +++ b/apis/system/index.go @@ -0,0 +1,40 @@ +package system + +import( + "github.com/gin-gonic/gin" +) + +const INDEX = ` + + + + +GO-ADMIN欢迎您 + + + + + + + + +` + + +func HelloWorld(c *gin.Context){ + c.Header("Content-Type", "text/html; charset=utf-8") + c.String(200, INDEX) +} diff --git a/apis/system/info.go b/apis/system/info.go index 51377a8b..482e6727 100644 --- a/apis/system/info.go +++ b/apis/system/info.go @@ -3,24 +3,23 @@ package system import ( "github.com/gin-gonic/gin" "go-admin/models" - "go-admin/pkg" - "go-admin/pkg/app" - "go-admin/pkg/utils" + "go-admin/tools" + "go-admin/tools/app" ) func GetInfo(c *gin.Context) { var roles = make([]string, 1) - roles[0] = utils.GetRoleName(c) + roles[0] = tools.GetRoleName(c) var permissions = make([]string, 1) permissions[0] = "*:*:*" RoleMenu := models.RoleMenu{} - RoleMenu.RoleId = utils.GetRoleId(c) + RoleMenu.RoleId = tools.GetRoleId(c) var mp = make(map[string]interface{}) mp["roles"] = roles - if utils.GetRoleName(c) == "admin" || utils.GetRoleName(c) == "系统管理员" { + if tools.GetRoleName(c) == "admin" || tools.GetRoleName(c) == "系统管理员" { mp["permissions"] = permissions } else { list, _ := RoleMenu.GetPermis() @@ -28,9 +27,9 @@ func GetInfo(c *gin.Context) { } sysuser := models.SysUser{} - sysuser.UserId = utils.GetUserId(c) + sysuser.UserId = tools.GetUserId(c) user, err := sysuser.Get() - pkg.HasError(err, "", 500) + tools.HasError(err, "", 500) mp["introduction"] = " am a super administrator" diff --git a/apis/system/menu.go b/apis/system/menu.go index ea2f1938..2f50a357 100644 --- a/apis/system/menu.go +++ b/apis/system/menu.go @@ -4,9 +4,8 @@ import ( "github.com/gin-gonic/gin" "github.com/gin-gonic/gin/binding" "go-admin/models" - "go-admin/pkg" - "go-admin/pkg/app" - "go-admin/pkg/utils" + "go-admin/tools" + "go-admin/tools/app" ) // @Summary Menu列表数据 @@ -20,11 +19,13 @@ import ( func GetMenuList(c *gin.Context) { var Menu models.Menu Menu.MenuName = c.Request.FormValue("menuName") - Menu.DataScope = utils.GetUserIdStr(c) + Menu.Visible = c.Request.FormValue("visible") + Menu.Title = c.Request.FormValue("title") + Menu.DataScope = tools.GetUserIdStr(c) result, err := Menu.SetMenu() - pkg.HasError(err, "抱歉未找到相关信息", -1) + tools.HasError(err, "抱歉未找到相关信息", -1) - app.OK(c,result,"") + app.OK(c, result, "") } // @Summary Menu列表数据 @@ -37,26 +38,26 @@ func GetMenuList(c *gin.Context) { // @Security Bearer func GetMenu(c *gin.Context) { var data models.Menu - id, err := utils.StringToInt(c.Param("id")) + id, err := tools.StringToInt(c.Param("id")) data.MenuId = id result, err := data.GetByMenuId() - pkg.HasError(err, "抱歉未找到相关信息", -1) - app.OK(c,result,"") + tools.HasError(err, "抱歉未找到相关信息", -1) + app.OK(c, result, "") } func GetMenuTreeRoleselect(c *gin.Context) { var Menu models.Menu var SysRole models.SysRole - id, err := utils.StringToInt(c.Param("roleId")) + id, err := tools.StringToInt(c.Param("roleId")) SysRole.RoleId = id result, err := Menu.SetMenuLable() - pkg.HasError(err, "抱歉未找到相关信息", -1) + tools.HasError(err, "抱歉未找到相关信息", -1) menuIds := make([]int, 0) if id != 0 { menuIds, err = SysRole.GetRoleMeunId() - pkg.HasError(err, "抱歉未找到相关信息", -1) + tools.HasError(err, "抱歉未找到相关信息", -1) } - app.Custum(c,gin.H{ + app.Custum(c, gin.H{ "code": 200, "menus": result, "checkedKeys": menuIds, @@ -75,8 +76,8 @@ func GetMenuTreeRoleselect(c *gin.Context) { func GetMenuTreeelect(c *gin.Context) { var data models.Menu result, err := data.SetMenuLable() - pkg.HasError(err, "抱歉未找到相关信息", -1) - app.OK(c,result,"") + tools.HasError(err, "抱歉未找到相关信息", -1) + app.OK(c, result, "") } // @Summary 创建菜单 @@ -97,11 +98,11 @@ func GetMenuTreeelect(c *gin.Context) { func InsertMenu(c *gin.Context) { var data models.Menu err := c.BindWith(&data, binding.JSON) - pkg.HasError(err, "抱歉未找到相关信息", -1) - data.CreateBy = utils.GetUserIdStr(c) + tools.HasError(err, "抱歉未找到相关信息", -1) + data.CreateBy = tools.GetUserIdStr(c) result, err := data.Create() - pkg.HasError(err, "抱歉未找到相关信息", -1) - app.OK(c,result,"") + tools.HasError(err, "抱歉未找到相关信息", -1) + app.OK(c, result, "") } // @Summary 修改菜单 @@ -118,11 +119,11 @@ func InsertMenu(c *gin.Context) { func UpdateMenu(c *gin.Context) { var data models.Menu err2 := c.BindWith(&data, binding.JSON) - data.UpdateBy = utils.GetUserIdStr(c) - pkg.HasError(err2, "修改失败", -1) + data.UpdateBy = tools.GetUserIdStr(c) + tools.HasError(err2, "修改失败", -1) _, err := data.Update(data.MenuId) - pkg.HasError(err, "", 501) - app.OK(c,"","修改成功") + tools.HasError(err, "", 501) + app.OK(c, "", "修改成功") } @@ -135,11 +136,11 @@ func UpdateMenu(c *gin.Context) { // @Router /api/v1/menu/{id} [delete] func DeleteMenu(c *gin.Context) { var data models.Menu - id, err := utils.StringToInt(c.Param("id")) - data.UpdateBy = utils.GetUserIdStr(c) + id, err := tools.StringToInt(c.Param("id")) + data.UpdateBy = tools.GetUserIdStr(c) _, err = data.Delete(id) - pkg.HasError(err, "删除失败", 500) - app.OK(c,"","删除成功") + tools.HasError(err, "删除失败", 500) + app.OK(c, "", "删除成功") } // @Summary 根据角色名称获取菜单列表数据(左菜单使用) @@ -152,9 +153,9 @@ func DeleteMenu(c *gin.Context) { // @Security Bearer func GetMenuRole(c *gin.Context) { var Menu models.Menu - result, err := Menu.SetMenuRole(utils.GetRoleName(c)) - pkg.HasError(err, "获取失败", 500) - app.OK(c,result,"") + result, err := Menu.SetMenuRole(tools.GetRoleName(c)) + tools.HasError(err, "获取失败", 500) + app.OK(c, result, "") } // @Summary 获取角色对应的菜单id数组 @@ -168,8 +169,8 @@ func GetMenuRole(c *gin.Context) { func GetMenuIDS(c *gin.Context) { var data models.RoleMenu data.RoleName = c.GetString("role") - data.UpdateBy = utils.GetUserIdStr(c) + data.UpdateBy = tools.GetUserIdStr(c) result, err := data.GetIDS() - pkg.HasError(err, "获取失败", 500) - app.OK(c,result,"") + tools.HasError(err, "获取失败", 500) + app.OK(c, result, "") } diff --git a/apis/system/post.go b/apis/system/post.go index cf084664..643c41b0 100644 --- a/apis/system/post.go +++ b/apis/system/post.go @@ -3,9 +3,8 @@ package system import ( "github.com/gin-gonic/gin" "go-admin/models" - "go-admin/pkg" - "go-admin/pkg/app" - "go-admin/pkg/utils" + "go-admin/tools" + "go-admin/tools/app" ) // @Summary 职位列表数据 @@ -14,7 +13,7 @@ import ( // @Param name query string false "name" // @Param id query string false "id" // @Param position query string false "position" -// @Success 200 {object} models.Response "{"code": 200, "data": [...]}" +// @Success 200 {object} app.Response "{"code": 200, "data": [...]}" // @Router /api/v1/post [get] // @Security func GetPostList(c *gin.Context) { @@ -24,21 +23,21 @@ func GetPostList(c *gin.Context) { var pageIndex = 1 if size := c.Request.FormValue("pageSize"); size != "" { - pageSize = pkg.StrToInt(err, size) + pageSize = tools.StrToInt(err, size) } if index := c.Request.FormValue("pageIndex"); index != "" { - pageIndex = pkg.StrToInt(err, index) + pageIndex = tools.StrToInt(err, index) } data.PostName = c.Request.FormValue("postName") id := c.Request.FormValue("postId") - data.PostId, _ = utils.StringToInt(id) + data.PostId, _ = tools.StringToInt(id) data.PostName = c.Request.FormValue("postName") - data.DataScope = utils.GetUserIdStr(c) + data.DataScope = tools.GetUserIdStr(c) result, count, err := data.GetPage(pageSize, pageIndex) - pkg.HasError(err, "", -1) + tools.HasError(err, "", -1) app.PageOK(c, result, count, pageIndex, pageSize, "") } @@ -46,14 +45,14 @@ func GetPostList(c *gin.Context) { // @Description 获取JSON // @Tags 字典数据 // @Param postId path int true "postId" -// @Success 200 {object} models.Response "{"code": 200, "data": [...]}" +// @Success 200 {object} app.Response "{"code": 200, "data": [...]}" // @Router /api/v1/post/{postId} [get] // @Security func GetPost(c *gin.Context) { var Post models.Post - Post.PostId, _ = utils.StringToInt(c.Param("postId")) + Post.PostId, _ = tools.StringToInt(c.Param("postId")) result, err := Post.Get() - pkg.HasError(err, "抱歉未找到相关信息", -1) + tools.HasError(err, "抱歉未找到相关信息", -1) app.OK(c,result,"") } @@ -70,10 +69,10 @@ func GetPost(c *gin.Context) { func InsertPost(c *gin.Context) { var data models.Post err := c.Bind(&data) - data.CreateBy = utils.GetUserIdStr(c) - pkg.HasError(err, "", 500) + data.CreateBy = tools.GetUserIdStr(c) + tools.HasError(err, "", 500) result, err := data.Create() - pkg.HasError(err, "", -1) + tools.HasError(err, "", -1) app.OK(c,result,"") } @@ -91,10 +90,10 @@ func UpdatePost(c *gin.Context) { var data models.Post err := c.Bind(&data) - data.UpdateBy = utils.GetUserIdStr(c) - pkg.HasError(err, "", -1) + data.UpdateBy = tools.GetUserIdStr(c) + tools.HasError(err, "", -1) result, err := data.Update(data.PostId) - pkg.HasError(err, "", -1) + tools.HasError(err, "", -1) app.OK(c,result,"修改成功") } @@ -107,9 +106,9 @@ func UpdatePost(c *gin.Context) { // @Router /api/v1/post/{postId} [delete] func DeletePost(c *gin.Context) { var data models.Post - id, err := utils.StringToInt(c.Param("postId")) - data.UpdateBy = utils.GetUserIdStr(c) + id, err := tools.StringToInt(c.Param("postId")) + data.UpdateBy = tools.GetUserIdStr(c) _, err = data.Delete(id) - pkg.HasError(err, "删除失败", 500) + tools.HasError(err, "删除失败", 500) app.OK(c,"","删除成功") } diff --git a/apis/system/role.go b/apis/system/role.go index 5e9fe37e..b762806f 100644 --- a/apis/system/role.go +++ b/apis/system/role.go @@ -4,9 +4,8 @@ import ( "github.com/gin-gonic/gin" "github.com/gin-gonic/gin/binding" "go-admin/models" - "go-admin/pkg" - "go-admin/pkg/app" - "go-admin/pkg/utils" + "go-admin/tools" + "go-admin/tools/app" ) // @Summary 角色列表数据 @@ -17,7 +16,7 @@ import ( // @Param roleKey query string false "roleKey" // @Param pageSize query int false "页条数" // @Param pageIndex query int false "页码" -// @Success 200 {object} models.Response "{"code": 200, "data": [...]}" +// @Success 200 {object} app.Response "{"code": 200, "data": [...]}" // @Router /api/v1/rolelist [get] // @Security func GetRoleList(c *gin.Context) { @@ -27,19 +26,19 @@ func GetRoleList(c *gin.Context) { var pageIndex = 1 if size := c.Request.FormValue("pageSize"); size != "" { - pageSize = pkg.StrToInt(err, size) + pageSize = tools.StrToInt(err, size) } if index := c.Request.FormValue("pageIndex"); index != "" { - pageIndex = pkg.StrToInt(err, index) + pageIndex = tools.StrToInt(err, index) } data.RoleKey = c.Request.FormValue("roleKey") data.RoleName = c.Request.FormValue("roleName") data.Status = c.Request.FormValue("status") - data.DataScope = utils.GetUserIdStr(c) + data.DataScope = tools.GetUserIdStr(c) result, count, err := data.GetPage(pageSize, pageIndex) - pkg.HasError(err, "", -1) + tools.HasError(err, "", -1) app.PageOK(c, result, count, pageIndex, pageSize, "") } @@ -54,11 +53,11 @@ func GetRoleList(c *gin.Context) { // @Security Bearer func GetRole(c *gin.Context) { var Role models.SysRole - Role.RoleId, _ = utils.StringToInt(c.Param("roleId")) + Role.RoleId, _ = tools.StringToInt(c.Param("roleId")) result, err := Role.Get() menuIds := make([]int, 0) menuIds, err = Role.GetRoleMeunId() - pkg.HasError(err, "抱歉未找到相关信息", -1) + tools.HasError(err, "抱歉未找到相关信息", -1) result.MenuIds = menuIds app.OK(c, result, "") @@ -69,21 +68,21 @@ func GetRole(c *gin.Context) { // @Tags 角色/Role // @Accept application/json // @Product application/json -// @Param data body models.Config true "data" +// @Param data body models.SysRole true "data" // @Success 200 {string} string "{"code": 200, "message": "添加成功"}" // @Success 200 {string} string "{"code": -1, "message": "添加失败"}" // @Router /api/v1/role [post] func InsertRole(c *gin.Context) { var data models.SysRole - data.CreateBy = utils.GetUserIdStr(c) + data.CreateBy = tools.GetUserIdStr(c) err := c.BindWith(&data, binding.JSON) - pkg.HasError(err, "", 500) + tools.HasError(err, "", 500) id, err := data.Insert() data.RoleId = id - pkg.HasError(err, "", -1) + tools.HasError(err, "", -1) var t models.RoleMenu _, err = t.Insert(id, data.MenuIds) - pkg.HasError(err, "", -1) + tools.HasError(err, "", -1) app.OK(c, data, "添加成功") } @@ -98,32 +97,32 @@ func InsertRole(c *gin.Context) { // @Router /api/v1/role [put] func UpdateRole(c *gin.Context) { var data models.SysRole - data.UpdateBy = utils.GetUserIdStr(c) + data.UpdateBy = tools.GetUserIdStr(c) err := c.Bind(&data) - pkg.HasError(err, "数据解析失败", -1) + tools.HasError(err, "数据解析失败", -1) result, err := data.Update(data.RoleId) var t models.RoleMenu _, err = t.DeleteRoleMenu(data.RoleId) - pkg.HasError(err, "添加失败1", -1) + tools.HasError(err, "添加失败1", -1) _, err2 := t.Insert(data.RoleId, data.MenuIds) - pkg.HasError(err2, "添加失败2", -1) + tools.HasError(err2, "添加失败2", -1) app.OK(c, result, "修改成功") } func UpdateRoleDataScope(c *gin.Context) { var data models.SysRole - data.UpdateBy = utils.GetUserIdStr(c) + data.UpdateBy = tools.GetUserIdStr(c) err := c.Bind(&data) - pkg.HasError(err, "数据解析失败", -1) + tools.HasError(err, "数据解析失败", -1) result, err := data.Update(data.RoleId) var t models.SysRoleDept _, err = t.DeleteRoleDept(data.RoleId) - pkg.HasError(err, "添加失败1", -1) + tools.HasError(err, "添加失败1", -1) if data.DataScope == "2" { _, err2 := t.Insert(data.RoleId, data.DeptIds) - pkg.HasError(err2, "添加失败2", -1) + tools.HasError(err2, "添加失败2", -1) } app.OK(c, result, "修改成功") } @@ -137,13 +136,13 @@ func UpdateRoleDataScope(c *gin.Context) { // @Router /api/v1/role/{roleId} [delete] func DeleteRole(c *gin.Context) { var Role models.SysRole - Role.UpdateBy = utils.GetUserIdStr(c) + Role.UpdateBy = tools.GetUserIdStr(c) - IDS := utils.IdsStrToIdsIntGroup("roleId", c) + IDS := tools.IdsStrToIdsIntGroup("roleId", c) _, err := Role.BatchDelete(IDS) - pkg.HasError(err, "删除失败1", -1) + tools.HasError(err, "删除失败1", -1) var t models.RoleMenu _, err = t.BatchDeleteRoleMenu(IDS) - pkg.HasError(err, "删除失败1", -1) + tools.HasError(err, "删除失败1", -1) app.OK(c, "", "删除成功") } diff --git a/apis/system/rolemenu.go b/apis/system/rolemenu.go index 1a4e06ff..ca96fc8b 100644 --- a/apis/system/rolemenu.go +++ b/apis/system/rolemenu.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/gin-gonic/gin" "go-admin/models" - "go-admin/pkg/app" + "go-admin/tools/app" "net/http" ) diff --git a/apis/system/sysuser.go b/apis/system/sysuser.go index d18590ab..0d16a50c 100644 --- a/apis/system/sysuser.go +++ b/apis/system/sysuser.go @@ -5,9 +5,8 @@ import ( "github.com/gin-gonic/gin/binding" "github.com/google/uuid" "go-admin/models" - "go-admin/pkg" - "go-admin/pkg/app" - "go-admin/pkg/utils" + "go-admin/tools" + "go-admin/tools/app" "log" ) @@ -27,25 +26,27 @@ func GetSysUserList(c *gin.Context) { size := c.Request.FormValue("pageSize") if size != "" { - pageSize = pkg.StrToInt(err, size) + pageSize = tools.StrToInt(err, size) } index := c.Request.FormValue("pageIndex") if index != "" { - pageIndex = pkg.StrToInt(err, index) + pageIndex = tools.StrToInt(err, index) } data.Username = c.Request.FormValue("userName") + data.Status = c.Request.FormValue("status") + data.Phone = c.Request.FormValue("phone") postId := c.Request.FormValue("postId") - data.PostId, _ = utils.StringToInt(postId) + data.PostId, _ = tools.StringToInt(postId) deptId := c.Request.FormValue("deptId") - data.DeptId, _ = utils.StringToInt(deptId) + data.DeptId, _ = tools.StringToInt(deptId) - data.DataScope = utils.GetUserIdStr(c) + data.DataScope = tools.GetUserIdStr(c) result, count, err := data.GetPage(pageSize, pageIndex) - pkg.HasError(err, "", -1) + tools.HasError(err, "", -1) app.PageOK(c, result, count, pageIndex, pageSize, "") } @@ -54,14 +55,14 @@ func GetSysUserList(c *gin.Context) { // @Description 获取JSON // @Tags 用户 // @Param userId path int true "用户编码" -// @Success 200 {object} models.Response "{"code": 200, "data": [...]}" +// @Success 200 {object} app.Response "{"code": 200, "data": [...]}" // @Router /api/v1/sysUser/{userId} [get] // @Security func GetSysUser(c *gin.Context) { var SysUser models.SysUser - SysUser.UserId, _ = utils.StringToInt(c.Param("userId")) + SysUser.UserId, _ = tools.StringToInt(c.Param("userId")) result, err := SysUser.Get() - pkg.HasError(err, "抱歉未找到相关信息", -1) + tools.HasError(err, "抱歉未找到相关信息", -1) var SysRole models.SysRole var Post models.Post roles, err := SysRole.GetList() @@ -85,15 +86,15 @@ func GetSysUser(c *gin.Context) { // @Summary 获取当前登录用户 // @Description 获取JSON // @Tags 个人中心 -// @Success 200 {object} models.Response "{"code": 200, "data": [...]}" +// @Success 200 {object} app.Response "{"code": 200, "data": [...]}" // @Router /api/v1/user/profile [get] // @Security func GetSysUserProfile(c *gin.Context) { var SysUser models.SysUser - userId := utils.GetUserIdStr(c) - SysUser.UserId, _ = utils.StringToInt(userId) + userId := tools.GetUserIdStr(c) + SysUser.UserId, _ = tools.StringToInt(userId) result, err := SysUser.Get() - pkg.HasError(err, "抱歉未找到相关信息", -1) + tools.HasError(err, "抱歉未找到相关信息", -1) var SysRole models.SysRole var Post models.Post var Dept models.Dept @@ -125,7 +126,7 @@ func GetSysUserProfile(c *gin.Context) { // @Summary 获取用户角色和职位 // @Description 获取JSON // @Tags 用户 -// @Success 200 {object} models.Response "{"code": 200, "data": [...]}" +// @Success 200 {object} app.Response "{"code": 200, "data": [...]}" // @Router /api/v1/sysUser [get] // @Security func GetSysUserInit(c *gin.Context) { @@ -133,7 +134,7 @@ func GetSysUserInit(c *gin.Context) { var Post models.Post roles, err := SysRole.GetList() posts, err := Post.GetList() - pkg.HasError(err, "抱歉未找到相关信息", -1) + tools.HasError(err, "抱歉未找到相关信息", -1) mp := make(map[string]interface{}, 2) mp["roles"] = roles mp["posts"] = posts @@ -152,11 +153,11 @@ func GetSysUserInit(c *gin.Context) { func InsertSysUser(c *gin.Context) { var sysuser models.SysUser err := c.BindWith(&sysuser, binding.JSON) - pkg.HasError(err, "非法数据格式", 500) + tools.HasError(err, "非法数据格式", 500) - sysuser.CreateBy = utils.GetUserIdStr(c) + sysuser.CreateBy = tools.GetUserIdStr(c) id, err := sysuser.Insert() - pkg.HasError(err, "添加失败", 500) + tools.HasError(err, "添加失败", 500) app.OK(c, id, "添加成功") } @@ -172,10 +173,10 @@ func InsertSysUser(c *gin.Context) { func UpdateSysUser(c *gin.Context) { var data models.SysUser err := c.BindWith(&data, binding.JSON) - pkg.HasError(err, "数据解析失败", -1) - data.UpdateBy = utils.GetUserIdStr(c) + tools.HasError(err, "数据解析失败", -1) + data.UpdateBy = tools.GetUserIdStr(c) result, err := data.Update(data.UserId) - pkg.HasError(err, "修改失败", 500) + tools.HasError(err, "修改失败", 500) app.OK(c, result, "修改成功") } @@ -188,10 +189,10 @@ func UpdateSysUser(c *gin.Context) { // @Router /api/v1/sysuser/{userId} [delete] func DeleteSysUser(c *gin.Context) { var data models.SysUser - data.UpdateBy = utils.GetUserIdStr(c) - IDS := utils.IdsStrToIdsIntGroup("userId", c) + data.UpdateBy = tools.GetUserIdStr(c) + IDS := tools.IdsStrToIdsIntGroup("userId", c) result, err := data.BatchDelete(IDS) - pkg.HasError(err, "删除失败", 500) + tools.HasError(err, "删除失败", 500) app.OK(c, result, "删除成功") } @@ -214,9 +215,9 @@ func InsetSysUserAvatar(c *gin.Context) { _ = c.SaveUploadedFile(file, filPath) } sysuser := models.SysUser{} - sysuser.UserId = utils.GetUserId(c) + sysuser.UserId = tools.GetUserId(c) sysuser.Avatar = "/" + filPath - sysuser.UpdateBy = utils.GetUserIdStr(c) + sysuser.UpdateBy = tools.GetUserIdStr(c) sysuser.Update(sysuser.UserId) app.OK(c, filPath, "修改成功") } @@ -224,9 +225,9 @@ func InsetSysUserAvatar(c *gin.Context) { func SysUserUpdatePwd(c *gin.Context) { var pwd models.SysUserPwd err := c.Bind(&pwd) - pkg.HasError(err, "数据解析失败", 500) + tools.HasError(err, "数据解析失败", 500) sysuser := models.SysUser{} - sysuser.UserId = utils.GetUserId(c) + sysuser.UserId = tools.GetUserId(c) sysuser.SetPwd(pwd) app.OK(c, "", "密码修改成功") } diff --git a/apis/tools/dbcolumns.go b/apis/tools/dbcolumns.go index 05d1cc76..7219969f 100644 --- a/apis/tools/dbcolumns.go +++ b/apis/tools/dbcolumns.go @@ -3,8 +3,8 @@ package tools import ( "github.com/gin-gonic/gin" "go-admin/models/tools" - "go-admin/pkg" - "go-admin/pkg/app" + tools2 "go-admin/tools" + "go-admin/tools/app" "net/http" ) @@ -14,7 +14,7 @@ import ( // @Param tableName query string false "tableName / 数据表名称" // @Param pageSize query int false "pageSize / 页条数" // @Param pageIndex query int false "pageIndex / 页码" -// @Success 200 {object} models.Response "{"code": 200, "data": [...]}" +// @Success 200 {object} app.Response "{"code": 200, "data": [...]}" // @Router /api/v1/db/columns/page [get] func GetDBColumnList(c *gin.Context) { var data tools.DBColumns @@ -23,17 +23,17 @@ func GetDBColumnList(c *gin.Context) { var pageIndex = 1 if size := c.Request.FormValue("pageSize"); size != "" { - pageSize = pkg.StrToInt(err, size) + pageSize = tools2.StrToInt(err, size) } if index := c.Request.FormValue("pageIndex"); index != "" { - pageIndex = pkg.StrToInt(err, index) + pageIndex = tools2.StrToInt(err, index) } data.TableName = c.Request.FormValue("tableName") - pkg.Assert(data.TableName=="","table name cannot be empty!",500) + tools2.Assert(data.TableName=="","table name cannot be empty!",500) result, count, err := data.GetPage(pageSize, pageIndex) - pkg.HasError(err, "", -1) + tools2.HasError(err, "", -1) var mp = make(map[string]interface{}, 3) mp["list"] = result diff --git a/apis/tools/dbtables.go b/apis/tools/dbtables.go index a1688b50..0b6f2580 100644 --- a/apis/tools/dbtables.go +++ b/apis/tools/dbtables.go @@ -2,10 +2,10 @@ package tools import ( "github.com/gin-gonic/gin" - "go-admin/config" "go-admin/models/tools" - "go-admin/pkg" - "go-admin/pkg/app" + tools2 "go-admin/tools" + "go-admin/tools/app" + config2 "go-admin/tools/config" "net/http" ) @@ -15,7 +15,7 @@ import ( // @Param tableName query string false "tableName / 数据表名称" // @Param pageSize query int false "pageSize / 页条数" // @Param pageIndex query int false "pageIndex / 页码" -// @Success 200 {object} models.Response "{"code": 200, "data": [...]}" +// @Success 200 {object} app.Response "{"code": 200, "data": [...]}" // @Router /api/v1/db/tables/page [get] func GetDBTableList(c *gin.Context) { var res app.Response @@ -23,23 +23,23 @@ func GetDBTableList(c *gin.Context) { var err error var pageSize = 10 var pageIndex = 1 - if config.DatabaseConfig.Dbtype=="sqlite3"{ + if config2.DatabaseConfig.Dbtype=="sqlite3"{ res.Msg="对不起,sqlite3 暂不支持代码生成!" c.JSON(http.StatusOK, res.ReturnError(500)) return } if size := c.Request.FormValue("pageSize"); size != "" { - pageSize = pkg.StrToInt(err, size) + pageSize = tools2.StrToInt(err, size) } if index := c.Request.FormValue("pageIndex"); index != "" { - pageIndex = pkg.StrToInt(err, index) + pageIndex = tools2.StrToInt(err, index) } data.TableName = c.Request.FormValue("tableName") result, count, err := data.GetPage(pageSize, pageIndex) - pkg.HasError(err, "", -1) + tools2.HasError(err, "", -1) var mp = make(map[string]interface{}, 3) mp["list"] = result diff --git a/apis/tools/gen.go b/apis/tools/gen.go index 7adc57d7..b0f2a142 100644 --- a/apis/tools/gen.go +++ b/apis/tools/gen.go @@ -4,31 +4,40 @@ import ( "bytes" "github.com/gin-gonic/gin" "go-admin/models/tools" - "go-admin/pkg" - "go-admin/pkg/app" - "go-admin/pkg/utils" + tools2 "go-admin/tools" + "go-admin/tools/app" "net/http" "text/template" ) func Preview(c *gin.Context) { table := tools.SysTables{} - id, err := utils.StringToInt(c.Param("tableId")) - pkg.HasError(err, "", -1) + id, err := tools2.StringToInt(c.Param("tableId")) + tools2.HasError(err, "", -1) table.TableId = id t1, err := template.ParseFiles("template/model.go.template") - pkg.HasError(err, "", -1) + tools2.HasError(err, "", -1) t2, err := template.ParseFiles("template/api.go.template") - pkg.HasError(err, "", -1) + tools2.HasError(err, "", -1) + t3, err := template.ParseFiles("template/js.go.template") + tools2.HasError(err, "", -1) + t4, err := template.ParseFiles("template/vue.go.template") + tools2.HasError(err, "", -1) tab, _ := table.Get() var b1 bytes.Buffer err = t1.Execute(&b1, tab) var b2 bytes.Buffer err = t2.Execute(&b2, tab) + var b3 bytes.Buffer + err = t3.Execute(&b3, tab) + var b4 bytes.Buffer + err = t4.Execute(&b4, tab) mp := make(map[string]interface{}) mp["template/model.go.template"] = b1.String() mp["template/api.go.template"] = b2.String() + mp["template/js.go.template"] = b3.String() + mp["template/vue.go.template"] = b4.String() var res app.Response res.Data = mp diff --git a/apis/tools/systables.go b/apis/tools/systables.go index 0cef225e..ef69b9c7 100644 --- a/apis/tools/systables.go +++ b/apis/tools/systables.go @@ -3,9 +3,8 @@ package tools import ( "github.com/gin-gonic/gin" "go-admin/models/tools" - "go-admin/pkg" - "go-admin/pkg/app" - "go-admin/pkg/utils" + tools2 "go-admin/tools" + "go-admin/tools/app" "net/http" "strings" ) @@ -16,7 +15,7 @@ import ( // @Param tableName query string false "tableName / 数据表名称" // @Param pageSize query int false "pageSize / 页条数" // @Param pageIndex query int false "pageIndex / 页码" -// @Success 200 {object} models.Response "{"code": 200, "data": [...]}" +// @Success 200 {object} app.Response "{"code": 200, "data": [...]}" // @Router /api/v1/sys/tables/page [get] func GetSysTableList(c *gin.Context) { var data tools.SysTables @@ -25,16 +24,17 @@ func GetSysTableList(c *gin.Context) { var pageIndex = 1 if size := c.Request.FormValue("pageSize"); size != "" { - pageSize = pkg.StrToInt(err, size) + pageSize = tools2.StrToInt(err, size) } if index := c.Request.FormValue("pageIndex"); index != "" { - pageIndex = pkg.StrToInt(err, index) + pageIndex = tools2.StrToInt(err, index) } - data.TableName = c.Request.FormValue("tableName") + data.TBName = c.Request.FormValue("tableName") + data.TableComment = c.Request.FormValue("tableComment") result, count, err := data.GetPage(pageSize, pageIndex) - pkg.HasError(err, "", -1) + tools2.HasError(err, "", -1) var mp = make(map[string]interface{}, 3) mp["list"] = result @@ -52,14 +52,14 @@ func GetSysTableList(c *gin.Context) { // @Description 获取JSON // @Tags 工具 - 生成表 // @Param configKey path int true "configKey" -// @Success 200 {object} models.Response "{"code": 200, "data": [...]}" +// @Success 200 {object} app.Response "{"code": 200, "data": [...]}" // @Router /api/v1/sys/tables/info/{tableId} [get] // @Security func GetSysTables(c *gin.Context) { var data tools.SysTables - data.TableId, _ = utils.StringToInt(c.Param("tableId")) + data.TableId, _ = tools2.StringToInt(c.Param("tableId")) result, err := data.Get() - pkg.HasError(err, "抱歉未找到相关信息", -1) + tools2.HasError(err, "抱歉未找到相关信息", -1) var res app.Response res.Data = result @@ -84,13 +84,13 @@ func InsertSysTable(c *gin.Context) { var data tools.SysTables var dbTable tools.DBTables var dbColumn tools.DBColumns - data.TableName = c.Request.FormValue("tables") - data.CreateBy = utils.GetUserIdStr(c) + data.TBName = c.Request.FormValue("tables") + data.CreateBy = tools2.GetUserIdStr(c) - dbTable.TableName = data.TableName + dbTable.TableName = data.TBName dbtable, err := dbTable.Get() - dbColumn.TableName = data.TableName + dbColumn.TableName = data.TBName tablenamelist := strings.Split(dbColumn.TableName, "_") for i := 0; i < len(tablenamelist); i++ { strStart := string([]byte(tablenamelist[i])[:1]) @@ -103,7 +103,7 @@ func InsertSysTable(c *gin.Context) { data.Crud = true dbcolumn, err := dbColumn.GetList() - data.CreateBy = utils.GetUserIdStr(c) + data.CreateBy = tools2.GetUserIdStr(c) data.TableComment = dbtable.TableComment if dbtable.TableComment == "" { data.TableComment = data.ClassName @@ -163,7 +163,7 @@ func InsertSysTable(c *gin.Context) { } result, err := data.Create() - pkg.HasError(err, "", -1) + tools2.HasError(err, "", -1) var res app.Response res.Data = result @@ -185,10 +185,10 @@ func InsertSysTable(c *gin.Context) { func UpdateSysTable(c *gin.Context) { var data tools.SysTables err := c.Bind(&data) - pkg.HasError(err, "数据解析失败", -1) - data.UpdateBy = utils.GetUserIdStr(c) + tools2.HasError(err, "数据解析失败", -1) + data.UpdateBy = tools2.GetUserIdStr(c) result, err := data.Update() - pkg.HasError(err, "", -1) + tools2.HasError(err, "", -1) var res app.Response res.Data = result @@ -205,10 +205,9 @@ func UpdateSysTable(c *gin.Context) { // @Router /api/v1/sys/tables/info/{tableId} [delete] func DeleteSysTables(c *gin.Context) { var data tools.SysTables - id, err := utils.StringToInt(c.Param("tableId")) - data.TableId = id - _, err = data.Delete() - pkg.HasError(err, "删除失败", 500) + IDS := tools2.IdsStrToIdsIntGroup("tableId", c) + _, err := data.BatchDelete(IDS) + tools2.HasError(err, "删除失败", 500) var res app.Response res.Msg = "删除成功" c.JSON(http.StatusOK, res.ReturnOK()) diff --git a/cmd/api/server.go b/cmd/api/server.go new file mode 100644 index 00000000..0e48da24 --- /dev/null +++ b/cmd/api/server.go @@ -0,0 +1,94 @@ +package api + +import ( + "context" + "fmt" + "github.com/gin-gonic/gin" + "github.com/spf13/cobra" + "github.com/spf13/viper" + "go-admin/database" + "go-admin/router" + "go-admin/tools" + config2 "go-admin/tools/config" + "log" + "net/http" + "os" + "os/signal" + "time" +) + +var ( + config string + port string + mode string + StartCmd = &cobra.Command{ + Use: "server", + Short: "Start API server", + Example: "go-admin server config/settings.yml", + PreRun: func(cmd *cobra.Command, args []string) { + usage() + setup() + }, + RunE: func(cmd *cobra.Command, args []string) error { + return run() + }, + } +) + +func init() { + StartCmd.PersistentFlags().StringVarP(&config, "config", "c", "config/settings.yml", "Start server with provided configuration file") + StartCmd.PersistentFlags().StringVarP(&port, "port", "p", "8000", "Tcp port server listening on") + StartCmd.PersistentFlags().StringVarP(&mode, "mode", "m", "dev", "server mode ; eg:dev,test,prod") +} + +func usage() { + usageStr := `starting api server` + fmt.Printf("%s\n", usageStr) +} + +func setup() { + + //1. 读取配置 + config2.ConfigSetup(config) + //2. 设置日志 + tools.InitLogger() + //3. 初始化数据库链接 + database.Setup() + //4. 设置gin mode + if viper.GetString("settings.application.mode") == string(tools.ModeProd) { + gin.SetMode(gin.ReleaseMode) + } +} + +func run() error { + r := router.InitRouter() + + defer database.Eloquent.Close() + + srv := &http.Server{ + Addr: config2.ApplicationConfig.Host + ":" + config2.ApplicationConfig.Port, + Handler: r, + } + + go func() { + // 服务连接 + if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed { + log.Fatalf("listen: %s\n", err) + } + }() + log.Println("Server Run ", config2.ApplicationConfig.Host+":"+config2.ApplicationConfig.Port) + log.Println("Enter Control + C Shutdown Server") + // 等待中断信号以优雅地关闭服务器(设置 5 秒的超时时间) + quit := make(chan os.Signal) + signal.Notify(quit, os.Interrupt) + <-quit + log.Println("Shutdown Server ...") + + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + if err := srv.Shutdown(ctx); err != nil { + log.Fatal("Server Shutdown:", err) + } + log.Println("Server exiting") + return nil +} diff --git a/cmd/cobra.go b/cmd/cobra.go new file mode 100644 index 00000000..5e487a98 --- /dev/null +++ b/cmd/cobra.go @@ -0,0 +1,41 @@ +package cmd + +import ( + "errors" + "github.com/spf13/cobra" + "go-admin/cmd/api" + "go-admin/cmd/migrate" + "log" + "os" +) + +var rootCmd = &cobra.Command{ + Use: "go-admin", + Short: "-v", + SilenceUsage: true, + DisableAutoGenTag: true, + Long: `go-admin`, + Args: func(cmd *cobra.Command, args []string) error { + if len(args) < 1 { + return errors.New("requires at least one arg") + } + return nil + }, + PersistentPreRunE: func(*cobra.Command, []string) error { return nil }, + Run: func(cmd *cobra.Command, args []string) { + usageStr := `go-admin 1.0.0 欢迎使用,可以是用 -h 查看命令` + log.Printf("%s\n", usageStr) + }, +} + +func init() { + rootCmd.AddCommand(api.StartCmd) + rootCmd.AddCommand(migrate.StartCmd) +} + +//Execute : apply commands +func Execute() { + if err := rootCmd.Execute(); err != nil { + os.Exit(-1) + } +} diff --git a/cmd/migrate/server.go b/cmd/migrate/server.go new file mode 100644 index 00000000..897fb800 --- /dev/null +++ b/cmd/migrate/server.go @@ -0,0 +1,77 @@ +package migrate + +import ( + "fmt" + "go-admin/database" + orm "go-admin/database" + "go-admin/models" + "go-admin/models/gorm" + tools2 "go-admin/models/tools" + "go-admin/tools" + config2 "go-admin/tools/config" + "log" + + "github.com/spf13/cobra" +) + +var ( + config string + mode string + StartCmd = &cobra.Command{ + Use: "migrate", + Short: "migrate from struct to database", + Run: func(cmd *cobra.Command, args []string) { + run() + }, + } +) + +func init() { + StartCmd.PersistentFlags().StringVarP(&config, "config", "c", "config/settings.yml", "Start server with provided configuration file") + StartCmd.PersistentFlags().StringVarP(&mode, "mode", "m", "dev", "server mode ; eg:dev,test,prod") +} + +func run() { + usage := `start migrate` + fmt.Println(usage) + //1. 读取配置 + config2.ConfigSetup(config) + //2. 设置日志 + tools.InitLogger() + //3. 初始化数据库链接 + database.Setup() + //4. 数据库迁移 + _ = gorm.AutoMigrate(orm.Eloquent) + log.Println("数据库结构初始化成功!") + //5. 数据初始化完成 + if err := models.InitDb(); err != nil { + log.Fatal("数据库基础数据初始化失败!") + } + + usage = `数据库基础数据初始化成功` + fmt.Println(usage) +} + +func migrateModel() error { + if config2.DatabaseConfig.Dbtype == "mysql" { + orm.Eloquent = orm.Eloquent.Set("gorm:table_options", "ENGINE=InnoDB CHARSET=utf8mb4") + } + orm.Eloquent.SingularTable(true) + return orm.Eloquent.AutoMigrate( + new(models.CasbinRule), + new(tools2.SysTables), + new(tools2.SysColumns), + new(models.Dept), + new(models.Menu), + new(models.LoginLog), + new(models.SysOperLog), + new(models.RoleMenu), + new(models.SysRoleDept), + new(models.SysUser), + new(models.SysRole), + new(models.Post), + new(models.DictData), + new(models.SysConfig), + new(models.DictType), + ).Error +} diff --git a/config/db.sql b/config/db.sql index e65fbefa..7ce90c93 100644 --- a/config/db.sql +++ b/config/db.sql @@ -337,9 +337,6 @@ INSERT INTO `sys_menu` VALUES (46, NULL, '删除用户', NULL, '/api/v1/sysuser/ INSERT INTO `sys_menu` VALUES (50, 'Mangent', '基础信息', 'network', '/mangent', '/0/50', 'M', '无', '', 0, '1', '', 'Layout', 2, '0', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL); INSERT INTO `sys_menu` VALUES (51, 'Menu', '菜单管理', 'tree-table', 'menu', '/0/2/51', 'C', '无', 'system:sysmenu:list', 2, '1', '', '/menu/index', 3, '0', '1', '1', 0, '2020-04-11 15:52:48', '2020-04-12 11:16:30', NULL); INSERT INTO `sys_menu` VALUES (52, 'Role', '角色管理', 'peoples', 'role', '/0/2/52', 'C', '无', 'system:sysrole:list', 2, '1', '', '/role/index', 2, '0', '1', '1', 0, '2020-04-11 15:52:48', '2020-04-12 11:16:19', NULL); -INSERT INTO `sys_menu` VALUES (53, 'Doctor', '医生管理', 'pass', 'doctor', '/0/50/53', 'C', '无', '', 50, '1', '', '/doctor/index', 0, '0', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL); -INSERT INTO `sys_menu` VALUES (54, 'Calendar', '排班管理', 'calendar', 'calendar', '/0/50/54', 'C', '无', '', 50, '1', '', '/calendar/index', 0, '0', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL); -INSERT INTO `sys_menu` VALUES (55, 'Menber', '会员管理', 'vip', 'member', '/0/50/55', 'C', '无', '', 50, '1', '', '/member/index', 0, '0', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL); INSERT INTO `sys_menu` VALUES (56, 'Dept', '部门管理', 'tree', 'dept', '/0/2/56', 'C', '无', 'system:sysdept:list', 2, '0', '', '/dept/index', 4, '0', '1', '1', 0, '2020-04-11 15:52:48', '2020-04-12 11:16:47', NULL); INSERT INTO `sys_menu` VALUES (57, 'post', '岗位管理', 'pass', 'post', '/0/2/57', 'C', '无', 'system:syspost:list', 2, '0', '', '/post/index', 5, '0', '1', '1', 0, '2020-04-11 15:52:48', '2020-04-12 11:16:53', NULL); INSERT INTO `sys_menu` VALUES (58, 'Dict', '字典管理', 'education', 'dict', '/0/2/58', 'C', '无', 'system:sysdicttype:list', 2, '0', '', '/dict/index', 6, '0', '1', '1', 0, '2020-04-11 15:52:48', '2020-04-12 11:17:04', NULL); @@ -382,11 +379,6 @@ INSERT INTO `sys_menu` VALUES (94, NULL, '获取菜单树', 'bug', '/api/v1/menu INSERT INTO `sys_menu` VALUES (95, NULL, '获取角色菜单', 'bug', '/api/v1/rolemenu', '/0/63/205/95', 'A', 'GET', NULL, 205, NULL, NULL, NULL, 0, '1', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL); INSERT INTO `sys_menu` VALUES (96, NULL, '创建角色菜单', 'bug', '/api/v1/rolemenu', '/0/63/205/96', 'A', 'POST', NULL, 205, NULL, NULL, NULL, 0, '1', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL); INSERT INTO `sys_menu` VALUES (97, NULL, '删除用户菜单数据', 'bug', '/api/v1/rolemenu/:id', '/0/63/205/97', 'A', 'DELETE', NULL, 205, NULL, NULL, NULL, 0, '1', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL); -INSERT INTO `sys_menu` VALUES (98, NULL, '医生获取', 'bug', '/api/v1/doctor', '/0/63/208/98', 'A', 'GET', NULL, 208, NULL, NULL, NULL, 1, '1', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL); -INSERT INTO `sys_menu` VALUES (99, NULL, '创建医生', 'bug', '/api/v1/doctor', '/0/63/208/99', 'A', 'POST', NULL, 208, NULL, NULL, NULL, 0, '1', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL); -INSERT INTO `sys_menu` VALUES (100, NULL, '修改医生', 'bug', '/api/v1/doctor/:id', '/0/63/208/100', 'A', 'PUT', NULL, 208, NULL, NULL, NULL, 0, '1', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL); -INSERT INTO `sys_menu` VALUES (101, NULL, '删除医生', 'bug', '/api/v1/doctor/:id', '/0/63/208/101', 'A', 'DELETE', NULL, 208, NULL, NULL, NULL, 0, '1', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL); -INSERT INTO `sys_menu` VALUES (102, NULL, '添加医生头像', 'bug', '/api/v1/doctor/pic/', '/0/63/208/102', 'A', 'POST', NULL, 208, NULL, NULL, NULL, 0, '1', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL); INSERT INTO `sys_menu` VALUES (103, NULL, '部门菜单列表', 'bug', '/api/v1/deptList', '/0/63/203/103', 'A', 'GET', NULL, 203, NULL, NULL, NULL, 0, '1', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL); INSERT INTO `sys_menu` VALUES (104, NULL, '根据id获取部门信息', 'bug', '/api/v1/dept/:id', '/0/63/203/104', 'A', 'GET', NULL, 203, NULL, NULL, NULL, 0, '1', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL); INSERT INTO `sys_menu` VALUES (105, NULL, '创建部门', 'bug', '/api/v1/dept', '/0/63/203/105', 'A', 'POST', NULL, 203, NULL, NULL, NULL, 0, '1', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL); @@ -433,10 +425,6 @@ INSERT INTO `sys_menu` VALUES (203, '', '部门管理', 'tree', '', '/0/63/203', INSERT INTO `sys_menu` VALUES (204, '', '岗位管理', 'pass', '', '/0/63/204', 'C', '', '', 63, '0', '', '', 1, '1', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL); INSERT INTO `sys_menu` VALUES (205, '', '角色菜单管理', 'nested', '', '/0/63/205', 'C', '', '', 63, '0', '', '', 1, '1', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL); INSERT INTO `sys_menu` VALUES (206, '', '数据', '', '', '/0/63/69/206', 'C', 'PUT', '', 69, '0', '', '', 2, '1', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL); -INSERT INTO `sys_menu` VALUES (207, '', '会员管理', 'vip', '', '/0/63/207', 'C', 'DELETE', '', 63, '0', '', '', 1, '1', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL); -INSERT INTO `sys_menu` VALUES (208, '', '医生管理', 'theme', '', '/0/63/208', 'C', '', '', 63, '0', '', '', 1, '1', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL); -INSERT INTO `sys_menu` VALUES (209, '', '订单管理', 'tab', '', '/0/63/209', 'M', '', '', 63, '0', '', '', 1, '1', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL); -INSERT INTO `sys_menu` VALUES (210, '', '排班管理', 'calendar', '', '/0/63/210', 'C', 'DELETE', '', 63, '0', '', '', 1, '1', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL); INSERT INTO `sys_menu` VALUES (211, 'Log', '日志管理', 'log', '/log', '/0/2/211', 'M', '', '', 2, '0', '', '/log/index', 8, '0', '1', '1', 0, '2020-04-11 15:52:48', '2020-04-12 11:15:32', NULL); INSERT INTO `sys_menu` VALUES (212, 'LoginLog', '登录日志', 'logininfor', '/loginlog', '/0/2/211/212', 'C', '', 'system:sysloginlog:list', 211, '0', '', '/loginlog/index', 1, '0', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL); INSERT INTO `sys_menu` VALUES (213, NULL, '获取登录日志', 'bug', '/api/v1/loginloglist', '/0/63/214/213', 'A', 'GET', NULL, 214, NULL, NULL, NULL, 0, '1', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL); diff --git a/config/policy.csv b/config/policy.csv deleted file mode 100644 index fe74717e..00000000 --- a/config/policy.csv +++ /dev/null @@ -1,75 +0,0 @@ -p, admin, /api/v1/menulist, GET -p, admin, /api/v1/menu, POST -p, admin, /api/v1/dict/databytype/, GET -p, admin, /api/v1/menu/, PUT -p, admin, /api/v1/menu/, DELETE -p, admin, /api/v1/sysUserList, GET -p, admin, /api/v1/sysUser/:id, GET -p, admin, /api/v1/sysUser/, GET -p, admin, /api/v1/sysUser, POST -p, admin, /api/v1/sysUser, PUT -p, admin, /api/v1/sysUser/:id, DELETE -p, admin, /api/v1/user/profile, GET -p, admin, /api/v1/rolelist, GET -p, admin, /api/v1/role/:id, GET -p, admin, /api/v1/role, POST -p, admin, /api/v1/role, PUT -p, admin, /api/v1/role/:id, DELETE -p, admin, /api/v1/configList, GET -p, admin, /api/v1/config/:id, GET -p, admin, /api/v1/configKey/:id, GET -p, admin, /api/v1/config, POST -p, admin, /api/v1/config/, PUT -p, admin, /api/v1/config/:id, DELETE -p, admin, /api/v1/menurole, GET -p, admin, /api/v1/roleMenuTreeselect/:id, GET -p, admin, /api/v1/menuTreeselect, GET -p, admin, /api/v1/rolemenu, GET -p, admin, /api/v1/rolemenu, POST -p, admin, /api/v1/rolemenu/:id, DELETE -p, admin, /api/v1/doctor, GET -p, admin, /api/v1/doctor, POST -p, admin, /api/v1/doctor/:id, PUT -p, admin, /api/v1/doctor/:id, DELETE -p, admin, /api/v1/doctor/pic/, POST -p, admin, /api/v1/deptList, GET -p, admin, /api/v1/dept/:id, GET -p, admin, /api/v1/dept, POST -p, admin, /api/v1/dept, PUT -p, admin, /api/v1/dept/:id, DELETE -p, admin, /api/v1/dict/datalist, GET -p, admin, /api/v1/dict/data/:id, GET -p, admin, /api/v1/dict/databytype/:id, GET -p, admin, /api/v1/dict/data, POST -p, admin, /api/v1/dict/data/, PUT -p, admin, /api/v1/dict/data/:id, DELETE -p, admin, /api/v1/dict/typelist, GET -p, admin, /api/v1/dict/type/:id, GET -p, admin, /api/v1/dict/type, POST -p, admin, /api/v1/dict/type, PUT -p, admin, /api/v1/dict/type/:id, DELETE -p, admin, /api/v1/postlist, GET -p, admin, /api/v1/post/:id, GET -p, admin, /api/v1/post, POST -p, admin, /api/v1/post, PUT -p, admin, /api/v1/post/:id, DELETE -p, admin, /api/v1/calendar, GET -p, admin, /api/v1/calendar, POST -p, admin, /api/v1/calendar/:id, PUT -p, admin, /api/v1/calendar/:id, DELETE -p, admin, /api/v1/member, GET -p, admin, /api/v1/member, POST -p, admin, /api/v1/member/:id, PUT -p, admin, /api/v1/member/:id, DELETE -p, admin, /api/v1/orders, GET -p, admin, /api/v1/orders/:id, GET -p, admin, /api/v1/orders, POST -p, admin, /api/v1/orders/:id, PUT -p, admin, /api/v1/orders/:id, DELETE -p, admin, /api/v1/menu/:id, GET -p, admin, /api/v1/menu/:id, PUT -p, admin, /api/v1/menuids, GET -p, admin, /api/v1/loginloglist, GET -p, admin, /api/v1/loginlog/:id, DELETE -p, admin, /api/v1/operloglist, GET -p, admin, /api/v1/getinfo, GET \ No newline at end of file diff --git a/config/settings.yml b/config/settings.yml index b34b377d..90f87ce4 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -1,21 +1,21 @@ settings: application: - env: dev - envmsg: "谢谢您的参与,但为了大家更好的体验,所以本次提交就算了吧!\U0001F600\U0001F600\U0001F600" + mode: dev # dev开发环境 test测试环境 prod线上环境 + demomsg: "谢谢您的参与,但为了大家更好的体验,所以本次提交就算了吧!\U0001F600\U0001F600\U0001F600" host: 0.0.0.0 - isinit: false - logpath: temp/logs/log.txt name: testApp port: 8000 readtimeout: 1 writertimeout: 2 + log: + dir: temp/logs jwt: secret: go-admin timeout: 3600 database: - database: goadmin - dbtype: mysql # sqlite3 - host: 127.0.0.1 # sqlite3.db + name: goadmindb + dbtype: mysql + host: 127.0.0.1 password: 123456 port: 3306 username: root diff --git a/database/mysql.go b/database/mysql.go index 24394d40..378f1070 100644 --- a/database/mysql.go +++ b/database/mysql.go @@ -2,71 +2,83 @@ package database import ( "bytes" - "fmt" _ "github.com/go-sql-driver/mysql" //加载mysql "github.com/jinzhu/gorm" - _ "github.com/jinzhu/gorm/dialects/sqlite" - config2 "go-admin/config" + "go-admin/tools/config" + "log" "strconv" ) var Eloquent *gorm.DB -func init() { +var ( + DbType string + Host string + Port int + Name string + Username string + Password string +) - dbType := config2.DatabaseConfig.Dbtype - host := config2.DatabaseConfig.Host - port := config2.DatabaseConfig.Port - database := config2.DatabaseConfig.Database - username := config2.DatabaseConfig.Username - password := config2.DatabaseConfig.Password +func Setup() { - if dbType != "mysql" && dbType != "sqlite3" { - fmt.Println("db type unknow") + DbType = config.DatabaseConfig.Dbtype + Host = config.DatabaseConfig.Host + Port = config.DatabaseConfig.Port + Name = config.DatabaseConfig.Name + Username = config.DatabaseConfig.Username + Password = config.DatabaseConfig.Password + + if DbType != "mysql" && DbType != "sqlite3" { + log.Println("db type unknow") } var err error - var conn bytes.Buffer - conn.WriteString(username) - conn.WriteString(":") - conn.WriteString(password) - conn.WriteString("@tcp(") - conn.WriteString(host) - conn.WriteString(":") - conn.WriteString(strconv.Itoa(port)) - conn.WriteString(")") - conn.WriteString("/") - conn.WriteString(database) - conn.WriteString("?charset=utf8&parseTime=True&loc=Local&timeout=1000ms") + conn := GetMysqlConnect() - log.Println(conn.String()) + log.Println(conn) var db Database - if dbType == "mysql" { + if DbType == "mysql" { db = new(Mysql) + Eloquent, err = db.Open(DbType, conn) - Eloquent, err = db.Open(dbType, conn.String()) - - } else if dbType == "sqlite3" { + } else if DbType == "sqlite3" { db = new(SqlLite) - Eloquent, err = db.Open(dbType, host) + Eloquent, err = db.Open(DbType, Host) } else { panic("db type unknow") } - - Eloquent.LogMode(true) if err != nil { - log.Fatalln("%s connect error %v",dbType, err) + log.Fatalf("%s connect error %v", DbType, err) } else { - log.Println("%s connect success!",dbType) + log.Printf("%s connect success!", DbType) } + if Eloquent.Error != nil { - log.Fatalln("database error %v", Eloquent.Error) + log.Fatalf("database error %v", Eloquent.Error) } + Eloquent.LogMode(true) +} + +func GetMysqlConnect() string { + var conn bytes.Buffer + conn.WriteString(Username) + conn.WriteString(":") + conn.WriteString(Password) + conn.WriteString("@tcp(") + conn.WriteString(Host) + conn.WriteString(":") + conn.WriteString(strconv.Itoa(Port)) + conn.WriteString(")") + conn.WriteString("/") + conn.WriteString(Name) + conn.WriteString("?charset=utf8&parseTime=True&loc=Local&timeout=1000ms") + return conn.String() } type Database interface { diff --git a/database/sqlite3.go b/database/sqlite3.go new file mode 100644 index 00000000..16835513 --- /dev/null +++ b/database/sqlite3.go @@ -0,0 +1,7 @@ +// +build sqlite3 + +package database + +import ( + _ "github.com/jinzhu/gorm/dialects/sqlite" +) diff --git a/docs/docs.go b/docs/docs.go index 213f3271..d6ea2ddf 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -1,6 +1,6 @@ // GENERATED BY THE COMMAND ABOVE; DO NOT EDIT // This file was generated by swaggo/swag at -// 2020-03-19 00:24:21.426215 +0800 CST m=+0.087420189 +// 2020-04-29 23:00:58.67458 +0800 CST m=+0.080406457 package docs @@ -52,7 +52,7 @@ var doc = `{ "required": true, "schema": { "type": "object", - "$ref": "#/definitions/models.Config" + "$ref": "#/definitions/models.SysConfig" } } ], @@ -91,7 +91,7 @@ var doc = `{ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" } } } @@ -146,7 +146,7 @@ var doc = `{ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" } } } @@ -200,7 +200,81 @@ var doc = `{ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" + } + } + } + } + }, + "/api/v1/db/columns/page": { + "get": { + "description": "数据库表列分页列表 / database table column page list", + "tags": [ + "工具 / Tools" + ], + "summary": "分页列表数据 / page list data", + "parameters": [ + { + "type": "string", + "description": "tableName / 数据表名称", + "name": "tableName", + "in": "query" + }, + { + "type": "integer", + "description": "pageSize / 页条数", + "name": "pageSize", + "in": "query" + }, + { + "type": "integer", + "description": "pageIndex / 页码", + "name": "pageIndex", + "in": "query" + } + ], + "responses": { + "200": { + "description": "{\"code\": 200, \"data\": [...]}", + "schema": { + "$ref": "#/definitions/app.Response" + } + } + } + } + }, + "/api/v1/db/tables/page": { + "get": { + "description": "数据库表分页列表 / database table page list", + "tags": [ + "工具 / Tools" + ], + "summary": "分页列表数据 / page list data", + "parameters": [ + { + "type": "string", + "description": "tableName / 数据表名称", + "name": "tableName", + "in": "query" + }, + { + "type": "integer", + "description": "pageSize / 页条数", + "name": "pageSize", + "in": "query" + }, + { + "type": "integer", + "description": "pageIndex / 页码", + "name": "pageIndex", + "in": "query" + } + ], + "responses": { + "200": { + "description": "{\"code\": 200, \"data\": [...]}", + "schema": { + "$ref": "#/definitions/app.Response" } } } @@ -315,7 +389,7 @@ var doc = `{ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" } } } @@ -383,7 +457,7 @@ var doc = `{ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" } } } @@ -436,9 +510,9 @@ var doc = `{ "application/json" ], "tags": [ - "配置" + "字典数据" ], - "summary": "添加配置", + "summary": "添加字典数据", "parameters": [ { "description": "data", @@ -447,7 +521,7 @@ var doc = `{ "required": true, "schema": { "type": "object", - "$ref": "#/definitions/models.Config" + "$ref": "#/definitions/models.DictType" } } ], @@ -509,7 +583,7 @@ var doc = `{ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" } } } @@ -540,7 +614,7 @@ var doc = `{ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" } } } @@ -595,7 +669,7 @@ var doc = `{ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" } } } @@ -721,7 +795,7 @@ var doc = `{ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" } } } @@ -752,7 +826,7 @@ var doc = `{ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" } } } @@ -879,7 +953,7 @@ var doc = `{ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" } } } @@ -957,7 +1031,7 @@ var doc = `{ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" } } } @@ -1306,7 +1380,7 @@ var doc = `{ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" } } } @@ -1386,7 +1460,7 @@ var doc = `{ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" } } } @@ -1428,7 +1502,7 @@ var doc = `{ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" } } } @@ -1531,7 +1605,7 @@ var doc = `{ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" } } } @@ -1637,7 +1711,7 @@ var doc = `{ "required": true, "schema": { "type": "object", - "$ref": "#/definitions/models.Config" + "$ref": "#/definitions/models.SysRole" } } ], @@ -1725,7 +1799,7 @@ var doc = `{ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" } } } @@ -1759,40 +1833,6 @@ var doc = `{ } } } - }, - "post": { - "description": "获取JSON", - "consumes": [ - "application/x-www-form-urlencoded" - ], - "tags": [ - "角色菜单" - ], - "summary": "创建角色菜单", - "parameters": [ - { - "type": "string", - "description": "role_id", - "name": "role_id", - "in": "formData", - "required": true - }, - { - "type": "string", - "description": "menu_id", - "name": "menu_id", - "in": "formData", - "required": true - } - ], - "responses": { - "200": { - "description": "{\"code\": -1, \"message\": \"添加失败\"}", - "schema": { - "type": "string" - } - } - } } }, "/api/v1/rolemenu/{id}": { @@ -1827,6 +1867,166 @@ var doc = `{ } } }, + "/api/v1/sys/tables/info": { + "put": { + "security": [ + { + "Bearer": [] + } + ], + "description": "修改表结构", + "consumes": [ + "application/json" + ], + "tags": [ + "工具 - 生成表" + ], + "summary": "修改表结构", + "parameters": [ + { + "description": "body", + "name": "data", + "in": "body", + "required": true, + "schema": { + "type": "object", + "$ref": "#/definitions/models.Dept" + } + } + ], + "responses": { + "200": { + "description": "{\"code\": -1, \"message\": \"添加失败\"}", + "schema": { + "type": "string" + } + } + } + }, + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "添加表结构", + "consumes": [ + "application/json" + ], + "tags": [ + "工具 - 生成表" + ], + "summary": "添加表结构", + "parameters": [ + { + "type": "string", + "description": "tableName / 数据表名称", + "name": "tables", + "in": "query" + } + ], + "responses": { + "200": { + "description": "{\"code\": -1, \"message\": \"添加失败\"}", + "schema": { + "type": "string" + } + } + } + } + }, + "/api/v1/sys/tables/info/{tableId}": { + "get": { + "security": [ + { + "": [] + } + ], + "description": "获取JSON", + "tags": [ + "工具 - 生成表" + ], + "summary": "获取配置", + "parameters": [ + { + "type": "integer", + "description": "configKey", + "name": "configKey", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "{\"code\": 200, \"data\": [...]}", + "schema": { + "$ref": "#/definitions/app.Response" + } + } + } + }, + "delete": { + "description": "删除表结构", + "tags": [ + "工具 - 生成表" + ], + "summary": "删除表结构", + "parameters": [ + { + "type": "integer", + "description": "tableId", + "name": "tableId", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "{\"code\": -1, \"message\": \"删除失败\"}", + "schema": { + "type": "string" + } + } + } + } + }, + "/api/v1/sys/tables/page": { + "get": { + "description": "生成表分页列表", + "tags": [ + "工具 - 生成表" + ], + "summary": "分页列表数据", + "parameters": [ + { + "type": "string", + "description": "tableName / 数据表名称", + "name": "tableName", + "in": "query" + }, + { + "type": "integer", + "description": "pageSize / 页条数", + "name": "pageSize", + "in": "query" + }, + { + "type": "integer", + "description": "pageIndex / 页码", + "name": "pageIndex", + "in": "query" + } + ], + "responses": { + "200": { + "description": "{\"code\": 200, \"data\": [...]}", + "schema": { + "$ref": "#/definitions/app.Response" + } + } + } + } + }, "/api/v1/sysUser": { "get": { "security": [ @@ -1843,7 +2043,7 @@ var doc = `{ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" } } } @@ -1904,7 +2104,7 @@ var doc = `{ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" } } } @@ -1996,43 +2196,6 @@ var doc = `{ } } }, - "/api/v1/tables/page": { - "get": { - "description": "数据库表分页列表 / database table page list", - "tags": [ - "工具 / Tools" - ], - "summary": "分页列表数据 / page list data", - "parameters": [ - { - "type": "string", - "description": "tableName / 数据表名称", - "name": "tableName", - "in": "query" - }, - { - "type": "integer", - "description": "pageSize / 页条数", - "name": "pageSize", - "in": "query" - }, - { - "type": "integer", - "description": "pageIndex / 页码", - "name": "pageIndex", - "in": "query" - } - ], - "responses": { - "200": { - "description": "{\"code\": 200, \"data\": [...]}", - "schema": { - "$ref": "#/definitions/models.Response" - } - } - } - } - }, "/api/v1/user/profile": { "get": { "security": [ @@ -2049,7 +2212,7 @@ var doc = `{ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" } } } @@ -2147,19 +2310,7 @@ var doc = `{ "summary": "CPU 使用量", "responses": { "200": { - "description": "OK - Load average: 2.39, 2.13, 1.97 | Cores: 2", - "schema": { - "type": "string" - } - }, - "429": { - "description": "WARNING", - "schema": { - "type": "string" - } - }, - "500": { - "description": "CRITICAL", + "description": "OK", "schema": { "type": "string" } @@ -2231,19 +2382,7 @@ var doc = `{ "summary": "OS", "responses": { "200": { - "description": "OK - Free space: 455MB (0GB) / 8192MB (8GB) | Used: 5%", - "schema": { - "type": "string" - } - }, - "429": { - "description": "WARNING", - "schema": { - "type": "string" - } - }, - "500": { - "description": "CRITICAL", + "description": "OK", "schema": { "type": "string" } @@ -2263,19 +2402,7 @@ var doc = `{ "summary": "内存使用量", "responses": { "200": { - "description": "OK - Free space: 455MB (0GB) / 8192MB (8GB) | Used: 5%", - "schema": { - "type": "string" - } - }, - "429": { - "description": "WARNING", - "schema": { - "type": "string" - } - }, - "500": { - "description": "CRITICAL", + "description": "OK", "schema": { "type": "string" } @@ -2285,52 +2412,20 @@ var doc = `{ } }, "definitions": { - "models.Config": { + "app.Response": { "type": "object", "properties": { - "configId": { - "description": "编码", - "type": "integer" + "code": { + "description": "代码", + "type": "integer", + "example": 200 }, - "configKey": { - "description": "参数键名", - "type": "string" + "data": { + "description": "数据集", + "type": "object" }, - "configName": { - "description": "参数名称", - "type": "string" - }, - "configType": { - "description": "是否系统内置", - "type": "string" - }, - "configValue": { - "description": "参数键值", - "type": "string" - }, - "createBy": { - "type": "string" - }, - "createTime": { - "type": "string" - }, - "dataScope": { - "type": "string" - }, - "isDel": { - "type": "string" - }, - "params": { - "type": "string" - }, - "remark": { - "description": "备注", - "type": "string" - }, - "updateBy": { - "type": "string" - }, - "updateTime": { + "msg": { + "description": "消息", "type": "string" } } @@ -2347,32 +2442,30 @@ var doc = `{ "createBy": { "type": "string" }, - "createTime": { + "createdAt": { "type": "string" }, "dataScope": { "type": "string" }, - "deptId": { - "description": "部门编码", - "type": "integer", - "x-description": "标示", - "example": 1 - }, - "deptath": { + "deletedAt": { "type": "string" }, - "deptname": { + "deptId": { + "description": "部门编码", + "type": "integer" + }, + "deptName": { "description": "部门名称", "type": "string" }, + "deptPath": { + "type": "string" + }, "email": { "description": "邮箱", "type": "string" }, - "isDel": { - "type": "string" - }, "leader": { "description": "负责人", "type": "string" @@ -2380,7 +2473,7 @@ var doc = `{ "params": { "type": "string" }, - "parent_id": { + "parentId": { "description": "上级部门", "type": "integer" }, @@ -2399,7 +2492,7 @@ var doc = `{ "updateBy": { "type": "string" }, - "updateTime": { + "updatedAt": { "type": "string" } } @@ -2411,16 +2504,17 @@ var doc = `{ "description": "创建者", "type": "string" }, - "createTime": { - "description": "创建时间", + "createdAt": { "type": "string" }, "dataScope": { "type": "string" }, + "deletedAt": { + "type": "string" + }, "dictId": { - "type": "integer", - "example": 1 + "type": "integer" }, "dictName": { "description": "字典名称", @@ -2430,9 +2524,6 @@ var doc = `{ "description": "字典类型", "type": "string" }, - "isDel": { - "type": "string" - }, "params": { "type": "string" }, @@ -2448,8 +2539,7 @@ var doc = `{ "description": "更新者", "type": "string" }, - "updateTime": { - "description": "更新时间", + "updatedAt": { "type": "string" } } @@ -2488,14 +2578,16 @@ var doc = `{ "description": "创建人", "type": "string" }, - "createTime": { - "description": "创建时间", + "createdAt": { "type": "string" }, "dataScope": { "description": "数据", "type": "string" }, + "deletedAt": { + "type": "string" + }, "infoId": { "description": "主键", "type": "integer" @@ -2504,10 +2596,6 @@ var doc = `{ "description": "ip地址", "type": "string" }, - "isDel": { - "description": "是否删除", - "type": "string" - }, "loginLocation": { "description": "归属地", "type": "string" @@ -2524,7 +2612,6 @@ var doc = `{ "type": "string" }, "params": { - "description": "参数", "type": "string" }, "platform": { @@ -2543,11 +2630,10 @@ var doc = `{ "description": "更新者", "type": "string" }, - "updateTime": { - "description": "更新时间", + "updatedAt": { "type": "string" }, - "userName": { + "username": { "description": "用户名", "type": "string" } @@ -2574,16 +2660,19 @@ var doc = `{ "createBy": { "type": "string" }, - "createTime": { + "createdAt": { "type": "string" }, "dataScope": { "type": "string" }, + "deletedAt": { + "type": "string" + }, "icon": { "type": "string" }, - "isDel": { + "isFrame": { "type": "string" }, "is_select": { @@ -2628,7 +2717,7 @@ var doc = `{ "updateBy": { "type": "string" }, - "updateTime": { + "updatedAt": { "type": "string" }, "visible": { @@ -2642,16 +2731,14 @@ var doc = `{ "createBy": { "type": "string" }, - "createTime": { - "description": "创建时间", + "createdAt": { "type": "string" }, "dataScope": { "type": "string" }, - "isDel": { - "description": "是否删除", - "type": "integer" + "deletedAt": { + "type": "string" }, "params": { "type": "string" @@ -2662,9 +2749,7 @@ var doc = `{ }, "postId": { "description": "岗位编号", - "type": "integer", - "x-description": "标示", - "example": 1 + "type": "integer" }, "postName": { "description": "岗位名称", @@ -2685,26 +2770,57 @@ var doc = `{ "updateBy": { "type": "string" }, - "updateTime": { - "description": "最后修改时间", + "updatedAt": { "type": "string" } } }, - "models.Response": { + "models.SysConfig": { "type": "object", "properties": { - "code": { - "description": "代码", - "type": "integer", - "example": 200 + "configId": { + "description": "编码", + "type": "integer" }, - "data": { - "description": "数据集", - "type": "object" + "configKey": { + "description": "参数键名", + "type": "string" }, - "msg": { - "description": "错误消息", + "configName": { + "description": "参数名称", + "type": "string" + }, + "configType": { + "description": "是否系统内置", + "type": "string" + }, + "configValue": { + "description": "参数键值", + "type": "string" + }, + "createBy": { + "type": "string" + }, + "createdAt": { + "type": "string" + }, + "dataScope": { + "type": "string" + }, + "deletedAt": { + "type": "string" + }, + "params": { + "type": "string" + }, + "remark": { + "description": "备注", + "type": "string" + }, + "updateBy": { + "type": "string" + }, + "updatedAt": { "type": "string" } } @@ -2723,20 +2839,18 @@ var doc = `{ "description": "创建人", "type": "string" }, - "createTime": { - "description": "创建时间", + "createdAt": { "type": "string" }, "dataScope": { "description": "数据", "type": "string" }, - "deptName": { - "description": "部门名称", + "deletedAt": { "type": "string" }, - "isDel": { - "description": "是否删除", + "deptName": { + "description": "部门名称", "type": "string" }, "jsonResult": { @@ -2807,12 +2921,11 @@ var doc = `{ "description": "更新者", "type": "string" }, - "updateTime": { - "description": "更新时间", + "updatedAt": { "type": "string" }, "userAgent": { - "description": "us", + "description": "ua", "type": "string" } } @@ -2826,12 +2939,15 @@ var doc = `{ "createBy": { "type": "string" }, - "createTime": { + "createdAt": { "type": "string" }, "dataScope": { "type": "string" }, + "deletedAt": { + "type": "string" + }, "deptIds": { "type": "array", "items": { @@ -2841,9 +2957,6 @@ var doc = `{ "flag": { "type": "string" }, - "isDel": { - "type": "string" - }, "menuIds": { "type": "array", "items": { @@ -2879,7 +2992,7 @@ var doc = `{ "updateBy": { "type": "string" }, - "updateTime": { + "updatedAt": { "type": "string" } } @@ -2894,13 +3007,15 @@ var doc = `{ "createBy": { "type": "string" }, - "createTime": { - "description": "创建时间", + "createdAt": { "type": "string" }, "dataScope": { "type": "string" }, + "deletedAt": { + "type": "string" + }, "deptId": { "description": "部门编码", "type": "integer" @@ -2909,9 +3024,6 @@ var doc = `{ "description": "邮箱", "type": "string" }, - "isDel": { - "type": "string" - }, "nickName": { "description": "昵称", "type": "string" @@ -2953,8 +3065,7 @@ var doc = `{ "updateBy": { "type": "string" }, - "updateTime": { - "description": "修改时间", + "updatedAt": { "type": "string" }, "userId": { diff --git a/docs/swagger.json b/docs/swagger.json index 062c21e8..6bf520fe 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -34,7 +34,7 @@ "required": true, "schema": { "type": "object", - "$ref": "#/definitions/models.Config" + "$ref": "#/definitions/models.SysConfig" } } ], @@ -73,7 +73,7 @@ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" } } } @@ -128,7 +128,7 @@ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" } } } @@ -182,7 +182,81 @@ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" + } + } + } + } + }, + "/api/v1/db/columns/page": { + "get": { + "description": "数据库表列分页列表 / database table column page list", + "tags": [ + "工具 / Tools" + ], + "summary": "分页列表数据 / page list data", + "parameters": [ + { + "type": "string", + "description": "tableName / 数据表名称", + "name": "tableName", + "in": "query" + }, + { + "type": "integer", + "description": "pageSize / 页条数", + "name": "pageSize", + "in": "query" + }, + { + "type": "integer", + "description": "pageIndex / 页码", + "name": "pageIndex", + "in": "query" + } + ], + "responses": { + "200": { + "description": "{\"code\": 200, \"data\": [...]}", + "schema": { + "$ref": "#/definitions/app.Response" + } + } + } + } + }, + "/api/v1/db/tables/page": { + "get": { + "description": "数据库表分页列表 / database table page list", + "tags": [ + "工具 / Tools" + ], + "summary": "分页列表数据 / page list data", + "parameters": [ + { + "type": "string", + "description": "tableName / 数据表名称", + "name": "tableName", + "in": "query" + }, + { + "type": "integer", + "description": "pageSize / 页条数", + "name": "pageSize", + "in": "query" + }, + { + "type": "integer", + "description": "pageIndex / 页码", + "name": "pageIndex", + "in": "query" + } + ], + "responses": { + "200": { + "description": "{\"code\": 200, \"data\": [...]}", + "schema": { + "$ref": "#/definitions/app.Response" } } } @@ -297,7 +371,7 @@ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" } } } @@ -365,7 +439,7 @@ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" } } } @@ -418,9 +492,9 @@ "application/json" ], "tags": [ - "配置" + "字典数据" ], - "summary": "添加配置", + "summary": "添加字典数据", "parameters": [ { "description": "data", @@ -429,7 +503,7 @@ "required": true, "schema": { "type": "object", - "$ref": "#/definitions/models.Config" + "$ref": "#/definitions/models.DictType" } } ], @@ -491,7 +565,7 @@ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" } } } @@ -522,7 +596,7 @@ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" } } } @@ -577,7 +651,7 @@ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" } } } @@ -703,7 +777,7 @@ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" } } } @@ -734,7 +808,7 @@ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" } } } @@ -861,7 +935,7 @@ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" } } } @@ -939,7 +1013,7 @@ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" } } } @@ -1288,7 +1362,7 @@ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" } } } @@ -1368,7 +1442,7 @@ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" } } } @@ -1410,7 +1484,7 @@ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" } } } @@ -1513,7 +1587,7 @@ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" } } } @@ -1619,7 +1693,7 @@ "required": true, "schema": { "type": "object", - "$ref": "#/definitions/models.Config" + "$ref": "#/definitions/models.SysRole" } } ], @@ -1707,7 +1781,7 @@ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" } } } @@ -1741,40 +1815,6 @@ } } } - }, - "post": { - "description": "获取JSON", - "consumes": [ - "application/x-www-form-urlencoded" - ], - "tags": [ - "角色菜单" - ], - "summary": "创建角色菜单", - "parameters": [ - { - "type": "string", - "description": "role_id", - "name": "role_id", - "in": "formData", - "required": true - }, - { - "type": "string", - "description": "menu_id", - "name": "menu_id", - "in": "formData", - "required": true - } - ], - "responses": { - "200": { - "description": "{\"code\": -1, \"message\": \"添加失败\"}", - "schema": { - "type": "string" - } - } - } } }, "/api/v1/rolemenu/{id}": { @@ -1809,6 +1849,166 @@ } } }, + "/api/v1/sys/tables/info": { + "put": { + "security": [ + { + "Bearer": [] + } + ], + "description": "修改表结构", + "consumes": [ + "application/json" + ], + "tags": [ + "工具 - 生成表" + ], + "summary": "修改表结构", + "parameters": [ + { + "description": "body", + "name": "data", + "in": "body", + "required": true, + "schema": { + "type": "object", + "$ref": "#/definitions/models.Dept" + } + } + ], + "responses": { + "200": { + "description": "{\"code\": -1, \"message\": \"添加失败\"}", + "schema": { + "type": "string" + } + } + } + }, + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "添加表结构", + "consumes": [ + "application/json" + ], + "tags": [ + "工具 - 生成表" + ], + "summary": "添加表结构", + "parameters": [ + { + "type": "string", + "description": "tableName / 数据表名称", + "name": "tables", + "in": "query" + } + ], + "responses": { + "200": { + "description": "{\"code\": -1, \"message\": \"添加失败\"}", + "schema": { + "type": "string" + } + } + } + } + }, + "/api/v1/sys/tables/info/{tableId}": { + "get": { + "security": [ + { + "": [] + } + ], + "description": "获取JSON", + "tags": [ + "工具 - 生成表" + ], + "summary": "获取配置", + "parameters": [ + { + "type": "integer", + "description": "configKey", + "name": "configKey", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "{\"code\": 200, \"data\": [...]}", + "schema": { + "$ref": "#/definitions/app.Response" + } + } + } + }, + "delete": { + "description": "删除表结构", + "tags": [ + "工具 - 生成表" + ], + "summary": "删除表结构", + "parameters": [ + { + "type": "integer", + "description": "tableId", + "name": "tableId", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "{\"code\": -1, \"message\": \"删除失败\"}", + "schema": { + "type": "string" + } + } + } + } + }, + "/api/v1/sys/tables/page": { + "get": { + "description": "生成表分页列表", + "tags": [ + "工具 - 生成表" + ], + "summary": "分页列表数据", + "parameters": [ + { + "type": "string", + "description": "tableName / 数据表名称", + "name": "tableName", + "in": "query" + }, + { + "type": "integer", + "description": "pageSize / 页条数", + "name": "pageSize", + "in": "query" + }, + { + "type": "integer", + "description": "pageIndex / 页码", + "name": "pageIndex", + "in": "query" + } + ], + "responses": { + "200": { + "description": "{\"code\": 200, \"data\": [...]}", + "schema": { + "$ref": "#/definitions/app.Response" + } + } + } + } + }, "/api/v1/sysUser": { "get": { "security": [ @@ -1825,7 +2025,7 @@ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" } } } @@ -1886,7 +2086,7 @@ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" } } } @@ -1978,43 +2178,6 @@ } } }, - "/api/v1/tables/page": { - "get": { - "description": "数据库表分页列表 / database table page list", - "tags": [ - "工具 / Tools" - ], - "summary": "分页列表数据 / page list data", - "parameters": [ - { - "type": "string", - "description": "tableName / 数据表名称", - "name": "tableName", - "in": "query" - }, - { - "type": "integer", - "description": "pageSize / 页条数", - "name": "pageSize", - "in": "query" - }, - { - "type": "integer", - "description": "pageIndex / 页码", - "name": "pageIndex", - "in": "query" - } - ], - "responses": { - "200": { - "description": "{\"code\": 200, \"data\": [...]}", - "schema": { - "$ref": "#/definitions/models.Response" - } - } - } - } - }, "/api/v1/user/profile": { "get": { "security": [ @@ -2031,7 +2194,7 @@ "200": { "description": "{\"code\": 200, \"data\": [...]}", "schema": { - "$ref": "#/definitions/models.Response" + "$ref": "#/definitions/app.Response" } } } @@ -2129,19 +2292,7 @@ "summary": "CPU 使用量", "responses": { "200": { - "description": "OK - Load average: 2.39, 2.13, 1.97 | Cores: 2", - "schema": { - "type": "string" - } - }, - "429": { - "description": "WARNING", - "schema": { - "type": "string" - } - }, - "500": { - "description": "CRITICAL", + "description": "OK", "schema": { "type": "string" } @@ -2213,19 +2364,7 @@ "summary": "OS", "responses": { "200": { - "description": "OK - Free space: 455MB (0GB) / 8192MB (8GB) | Used: 5%", - "schema": { - "type": "string" - } - }, - "429": { - "description": "WARNING", - "schema": { - "type": "string" - } - }, - "500": { - "description": "CRITICAL", + "description": "OK", "schema": { "type": "string" } @@ -2245,19 +2384,7 @@ "summary": "内存使用量", "responses": { "200": { - "description": "OK - Free space: 455MB (0GB) / 8192MB (8GB) | Used: 5%", - "schema": { - "type": "string" - } - }, - "429": { - "description": "WARNING", - "schema": { - "type": "string" - } - }, - "500": { - "description": "CRITICAL", + "description": "OK", "schema": { "type": "string" } @@ -2267,52 +2394,20 @@ } }, "definitions": { - "models.Config": { + "app.Response": { "type": "object", "properties": { - "configId": { - "description": "编码", - "type": "integer" + "code": { + "description": "代码", + "type": "integer", + "example": 200 }, - "configKey": { - "description": "参数键名", - "type": "string" + "data": { + "description": "数据集", + "type": "object" }, - "configName": { - "description": "参数名称", - "type": "string" - }, - "configType": { - "description": "是否系统内置", - "type": "string" - }, - "configValue": { - "description": "参数键值", - "type": "string" - }, - "createBy": { - "type": "string" - }, - "createTime": { - "type": "string" - }, - "dataScope": { - "type": "string" - }, - "isDel": { - "type": "string" - }, - "params": { - "type": "string" - }, - "remark": { - "description": "备注", - "type": "string" - }, - "updateBy": { - "type": "string" - }, - "updateTime": { + "msg": { + "description": "消息", "type": "string" } } @@ -2329,32 +2424,30 @@ "createBy": { "type": "string" }, - "createTime": { + "createdAt": { "type": "string" }, "dataScope": { "type": "string" }, - "deptId": { - "description": "部门编码", - "type": "integer", - "x-description": "标示", - "example": 1 - }, - "deptath": { + "deletedAt": { "type": "string" }, - "deptname": { + "deptId": { + "description": "部门编码", + "type": "integer" + }, + "deptName": { "description": "部门名称", "type": "string" }, + "deptPath": { + "type": "string" + }, "email": { "description": "邮箱", "type": "string" }, - "isDel": { - "type": "string" - }, "leader": { "description": "负责人", "type": "string" @@ -2362,7 +2455,7 @@ "params": { "type": "string" }, - "parent_id": { + "parentId": { "description": "上级部门", "type": "integer" }, @@ -2381,7 +2474,7 @@ "updateBy": { "type": "string" }, - "updateTime": { + "updatedAt": { "type": "string" } } @@ -2393,16 +2486,17 @@ "description": "创建者", "type": "string" }, - "createTime": { - "description": "创建时间", + "createdAt": { "type": "string" }, "dataScope": { "type": "string" }, + "deletedAt": { + "type": "string" + }, "dictId": { - "type": "integer", - "example": 1 + "type": "integer" }, "dictName": { "description": "字典名称", @@ -2412,9 +2506,6 @@ "description": "字典类型", "type": "string" }, - "isDel": { - "type": "string" - }, "params": { "type": "string" }, @@ -2430,8 +2521,7 @@ "description": "更新者", "type": "string" }, - "updateTime": { - "description": "更新时间", + "updatedAt": { "type": "string" } } @@ -2470,14 +2560,16 @@ "description": "创建人", "type": "string" }, - "createTime": { - "description": "创建时间", + "createdAt": { "type": "string" }, "dataScope": { "description": "数据", "type": "string" }, + "deletedAt": { + "type": "string" + }, "infoId": { "description": "主键", "type": "integer" @@ -2486,10 +2578,6 @@ "description": "ip地址", "type": "string" }, - "isDel": { - "description": "是否删除", - "type": "string" - }, "loginLocation": { "description": "归属地", "type": "string" @@ -2506,7 +2594,6 @@ "type": "string" }, "params": { - "description": "参数", "type": "string" }, "platform": { @@ -2525,11 +2612,10 @@ "description": "更新者", "type": "string" }, - "updateTime": { - "description": "更新时间", + "updatedAt": { "type": "string" }, - "userName": { + "username": { "description": "用户名", "type": "string" } @@ -2556,16 +2642,19 @@ "createBy": { "type": "string" }, - "createTime": { + "createdAt": { "type": "string" }, "dataScope": { "type": "string" }, + "deletedAt": { + "type": "string" + }, "icon": { "type": "string" }, - "isDel": { + "isFrame": { "type": "string" }, "is_select": { @@ -2610,7 +2699,7 @@ "updateBy": { "type": "string" }, - "updateTime": { + "updatedAt": { "type": "string" }, "visible": { @@ -2624,16 +2713,14 @@ "createBy": { "type": "string" }, - "createTime": { - "description": "创建时间", + "createdAt": { "type": "string" }, "dataScope": { "type": "string" }, - "isDel": { - "description": "是否删除", - "type": "integer" + "deletedAt": { + "type": "string" }, "params": { "type": "string" @@ -2644,9 +2731,7 @@ }, "postId": { "description": "岗位编号", - "type": "integer", - "x-description": "标示", - "example": 1 + "type": "integer" }, "postName": { "description": "岗位名称", @@ -2667,26 +2752,57 @@ "updateBy": { "type": "string" }, - "updateTime": { - "description": "最后修改时间", + "updatedAt": { "type": "string" } } }, - "models.Response": { + "models.SysConfig": { "type": "object", "properties": { - "code": { - "description": "代码", - "type": "integer", - "example": 200 + "configId": { + "description": "编码", + "type": "integer" }, - "data": { - "description": "数据集", - "type": "object" + "configKey": { + "description": "参数键名", + "type": "string" }, - "msg": { - "description": "错误消息", + "configName": { + "description": "参数名称", + "type": "string" + }, + "configType": { + "description": "是否系统内置", + "type": "string" + }, + "configValue": { + "description": "参数键值", + "type": "string" + }, + "createBy": { + "type": "string" + }, + "createdAt": { + "type": "string" + }, + "dataScope": { + "type": "string" + }, + "deletedAt": { + "type": "string" + }, + "params": { + "type": "string" + }, + "remark": { + "description": "备注", + "type": "string" + }, + "updateBy": { + "type": "string" + }, + "updatedAt": { "type": "string" } } @@ -2705,20 +2821,18 @@ "description": "创建人", "type": "string" }, - "createTime": { - "description": "创建时间", + "createdAt": { "type": "string" }, "dataScope": { "description": "数据", "type": "string" }, - "deptName": { - "description": "部门名称", + "deletedAt": { "type": "string" }, - "isDel": { - "description": "是否删除", + "deptName": { + "description": "部门名称", "type": "string" }, "jsonResult": { @@ -2789,12 +2903,11 @@ "description": "更新者", "type": "string" }, - "updateTime": { - "description": "更新时间", + "updatedAt": { "type": "string" }, "userAgent": { - "description": "us", + "description": "ua", "type": "string" } } @@ -2808,12 +2921,15 @@ "createBy": { "type": "string" }, - "createTime": { + "createdAt": { "type": "string" }, "dataScope": { "type": "string" }, + "deletedAt": { + "type": "string" + }, "deptIds": { "type": "array", "items": { @@ -2823,9 +2939,6 @@ "flag": { "type": "string" }, - "isDel": { - "type": "string" - }, "menuIds": { "type": "array", "items": { @@ -2861,7 +2974,7 @@ "updateBy": { "type": "string" }, - "updateTime": { + "updatedAt": { "type": "string" } } @@ -2876,13 +2989,15 @@ "createBy": { "type": "string" }, - "createTime": { - "description": "创建时间", + "createdAt": { "type": "string" }, "dataScope": { "type": "string" }, + "deletedAt": { + "type": "string" + }, "deptId": { "description": "部门编码", "type": "integer" @@ -2891,9 +3006,6 @@ "description": "邮箱", "type": "string" }, - "isDel": { - "type": "string" - }, "nickName": { "description": "昵称", "type": "string" @@ -2935,8 +3047,7 @@ "updateBy": { "type": "string" }, - "updateTime": { - "description": "修改时间", + "updatedAt": { "type": "string" }, "userId": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 0269582e..6cd4c299 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -1,37 +1,15 @@ definitions: - models.Config: + app.Response: properties: - configId: - description: 编码 + code: + description: 代码 + example: 200 type: integer - configKey: - description: 参数键名 - type: string - configName: - description: 参数名称 - type: string - configType: - description: 是否系统内置 - type: string - configValue: - description: 参数键值 - type: string - createBy: - type: string - createTime: - type: string - dataScope: - type: string - isDel: - type: string - params: - type: string - remark: - description: 备注 - type: string - updateBy: - type: string - updateTime: + data: + description: 数据集 + type: object + msg: + description: 消息 type: string type: object models.Dept: @@ -42,31 +20,29 @@ definitions: type: array createBy: type: string - createTime: + createdAt: type: string dataScope: type: string + deletedAt: + type: string deptId: description: 部门编码 - example: 1 type: integer - x-description: 标示 - deptath: - type: string - deptname: + deptName: description: 部门名称 type: string + deptPath: + type: string email: description: 邮箱 type: string - isDel: - type: string leader: description: 负责人 type: string params: type: string - parent_id: + parentId: description: 上级部门 type: integer phone: @@ -80,7 +56,7 @@ definitions: type: string updateBy: type: string - updateTime: + updatedAt: type: string type: object models.DictType: @@ -88,13 +64,13 @@ definitions: createBy: description: 创建者 type: string - createTime: - description: 创建时间 + createdAt: type: string dataScope: type: string + deletedAt: + type: string dictId: - example: 1 type: integer dictName: description: 字典名称 @@ -102,8 +78,6 @@ definitions: dictType: description: 字典类型 type: string - isDel: - type: string params: type: string remark: @@ -115,8 +89,7 @@ definitions: updateBy: description: 更新者 type: string - updateTime: - description: 更新时间 + updatedAt: type: string type: object models.Login: @@ -143,21 +116,19 @@ definitions: createBy: description: 创建人 type: string - createTime: - description: 创建时间 + createdAt: type: string dataScope: description: 数据 type: string + deletedAt: + type: string infoId: description: 主键 type: integer ipaddr: description: ip地址 type: string - isDel: - description: 是否删除 - type: string loginLocation: description: 归属地 type: string @@ -170,7 +141,6 @@ definitions: description: 系统 type: string params: - description: 参数 type: string platform: description: 固件 @@ -184,10 +154,9 @@ definitions: updateBy: description: 更新者 type: string - updateTime: - description: 更新时间 + updatedAt: type: string - userName: + username: description: 用户名 type: string type: object @@ -205,15 +174,17 @@ definitions: type: string createBy: type: string - createTime: + createdAt: type: string dataScope: type: string + deletedAt: + type: string icon: type: string is_select: type: boolean - isDel: + isFrame: type: string menuId: type: integer @@ -241,7 +212,7 @@ definitions: type: string updateBy: type: string - updateTime: + updatedAt: type: string visible: type: string @@ -250,14 +221,12 @@ definitions: properties: createBy: type: string - createTime: - description: 创建时间 + createdAt: type: string dataScope: type: string - isDel: - description: 是否删除 - type: integer + deletedAt: + type: string params: type: string postCode: @@ -265,9 +234,7 @@ definitions: type: string postId: description: 岗位编号 - example: 1 type: integer - x-description: 标示 postName: description: 岗位名称 type: string @@ -282,21 +249,42 @@ definitions: type: string updateBy: type: string - updateTime: - description: 最后修改时间 + updatedAt: type: string type: object - models.Response: + models.SysConfig: properties: - code: - description: 代码 - example: 200 + configId: + description: 编码 type: integer - data: - description: 数据集 - type: object - msg: - description: 错误消息 + configKey: + description: 参数键名 + type: string + configName: + description: 参数名称 + type: string + configType: + description: 是否系统内置 + type: string + configValue: + description: 参数键值 + type: string + createBy: + type: string + createdAt: + type: string + dataScope: + type: string + deletedAt: + type: string + params: + type: string + remark: + description: 备注 + type: string + updateBy: + type: string + updatedAt: type: string type: object models.SysOperLog: @@ -309,18 +297,16 @@ definitions: createBy: description: 创建人 type: string - createTime: - description: 创建时间 + createdAt: type: string dataScope: description: 数据 type: string + deletedAt: + type: string deptName: description: 部门名称 type: string - isDel: - description: 是否删除 - type: string jsonResult: description: 返回数据 type: string @@ -372,11 +358,10 @@ definitions: updateBy: description: 更新者 type: string - updateTime: - description: 更新时间 + updatedAt: type: string userAgent: - description: us + description: ua type: string type: object models.SysRole: @@ -385,18 +370,18 @@ definitions: type: boolean createBy: type: string - createTime: + createdAt: type: string dataScope: type: string + deletedAt: + type: string deptIds: items: type: integer type: array flag: type: string - isDel: - type: string menuIds: items: type: integer @@ -422,7 +407,7 @@ definitions: type: string updateBy: type: string - updateTime: + updatedAt: type: string type: object models.SysUser: @@ -432,19 +417,18 @@ definitions: type: string createBy: type: string - createTime: - description: 创建时间 + createdAt: type: string dataScope: type: string + deletedAt: + type: string deptId: description: 部门编码 type: integer email: description: 邮箱 type: string - isDel: - type: string nickName: description: 昵称 type: string @@ -475,8 +459,7 @@ definitions: type: string updateBy: type: string - updateTime: - description: 修改时间 + updatedAt: type: string userId: description: 编码 @@ -506,7 +489,7 @@ paths: name: data required: true schema: - $ref: '#/definitions/models.Config' + $ref: '#/definitions/models.SysConfig' type: object responses: "200": @@ -547,7 +530,7 @@ paths: "200": description: '{"code": 200, "data": [...]}' schema: - $ref: '#/definitions/models.Response' + $ref: '#/definitions/app.Response' security: - "": [] summary: 获取配置 @@ -566,7 +549,7 @@ paths: "200": description: '{"code": 200, "data": [...]}' schema: - $ref: '#/definitions/models.Response' + $ref: '#/definitions/app.Response' security: - "": [] summary: 获取配置 @@ -600,12 +583,60 @@ paths: "200": description: '{"code": 200, "data": [...]}' schema: - $ref: '#/definitions/models.Response' + $ref: '#/definitions/app.Response' security: - "": [] summary: 配置列表数据 tags: - 配置 + /api/v1/db/columns/page: + get: + description: 数据库表列分页列表 / database table column page list + parameters: + - description: tableName / 数据表名称 + in: query + name: tableName + type: string + - description: pageSize / 页条数 + in: query + name: pageSize + type: integer + - description: pageIndex / 页码 + in: query + name: pageIndex + type: integer + responses: + "200": + description: '{"code": 200, "data": [...]}' + schema: + $ref: '#/definitions/app.Response' + summary: 分页列表数据 / page list data + tags: + - 工具 / Tools + /api/v1/db/tables/page: + get: + description: 数据库表分页列表 / database table page list + parameters: + - description: tableName / 数据表名称 + in: query + name: tableName + type: string + - description: pageSize / 页条数 + in: query + name: pageSize + type: integer + - description: pageIndex / 页码 + in: query + name: pageIndex + type: integer + responses: + "200": + description: '{"code": 200, "data": [...]}' + schema: + $ref: '#/definitions/app.Response' + summary: 分页列表数据 / page list data + tags: + - 工具 / Tools /api/v1/dept: post: consumes: @@ -672,7 +703,7 @@ paths: "200": description: '{"code": 200, "data": [...]}' schema: - $ref: '#/definitions/models.Response' + $ref: '#/definitions/app.Response' security: - "": [] summary: 部门列表数据 @@ -715,7 +746,7 @@ paths: "200": description: '{"code": 200, "data": [...]}' schema: - $ref: '#/definitions/models.Response' + $ref: '#/definitions/app.Response' security: - "": [] summary: 分页部门列表数据 @@ -732,7 +763,7 @@ paths: name: data required: true schema: - $ref: '#/definitions/models.Config' + $ref: '#/definitions/models.DictType' type: object responses: "200": @@ -741,9 +772,9 @@ paths: type: string security: - Bearer: [] - summary: 添加配置 + summary: 添加字典数据 tags: - - 配置 + - 字典数据 put: consumes: - application/json @@ -795,7 +826,7 @@ paths: "200": description: '{"code": 200, "data": [...]}' schema: - $ref: '#/definitions/models.Response' + $ref: '#/definitions/app.Response' security: - "": [] summary: 通过编码获取字典数据 @@ -829,7 +860,7 @@ paths: "200": description: '{"code": 200, "data": [...]}' schema: - $ref: '#/definitions/models.Response' + $ref: '#/definitions/app.Response' security: - "": [] summary: 字典数据列表 @@ -848,7 +879,7 @@ paths: "200": description: '{"code": 200, "data": [...]}' schema: - $ref: '#/definitions/models.Response' + $ref: '#/definitions/app.Response' security: - "": [] summary: 通过字典类型获取字典数据 @@ -928,7 +959,7 @@ paths: "200": description: '{"code": 200, "data": [...]}' schema: - $ref: '#/definitions/models.Response' + $ref: '#/definitions/app.Response' security: - "": [] summary: 通过字典id获取字典类型 @@ -962,7 +993,7 @@ paths: "200": description: '{"code": 200, "data": [...]}' schema: - $ref: '#/definitions/models.Response' + $ref: '#/definitions/app.Response' security: - "": [] summary: 字典类型列表数据 @@ -1042,7 +1073,7 @@ paths: "200": description: '{"code": 200, "data": [...]}' schema: - $ref: '#/definitions/models.Response' + $ref: '#/definitions/app.Response' security: - "": [] summary: 通过编码获取登录日志 @@ -1076,7 +1107,7 @@ paths: "200": description: '{"code": 200, "data": [...]}' schema: - $ref: '#/definitions/models.Response' + $ref: '#/definitions/app.Response' security: - "": [] summary: 登录日志列表 @@ -1295,7 +1326,7 @@ paths: "200": description: '{"code": 200, "data": [...]}' schema: - $ref: '#/definitions/models.Response' + $ref: '#/definitions/app.Response' security: - "": [] summary: 通过编码获取登录日志 @@ -1346,7 +1377,7 @@ paths: "200": description: '{"code": 200, "data": [...]}' schema: - $ref: '#/definitions/models.Response' + $ref: '#/definitions/app.Response' security: - "": [] summary: 登录日志列表 @@ -1372,7 +1403,7 @@ paths: "200": description: '{"code": 200, "data": [...]}' schema: - $ref: '#/definitions/models.Response' + $ref: '#/definitions/app.Response' security: - "": [] summary: 职位列表数据 @@ -1452,7 +1483,7 @@ paths: "200": description: '{"code": 200, "data": [...]}' schema: - $ref: '#/definitions/models.Response' + $ref: '#/definitions/app.Response' security: - "": [] summary: 获取字典数据 @@ -1486,7 +1517,7 @@ paths: name: data required: true schema: - $ref: '#/definitions/models.Config' + $ref: '#/definitions/models.SysRole' type: object responses: "200": @@ -1561,7 +1592,7 @@ paths: "200": description: '{"code": 200, "data": [...]}' schema: - $ref: '#/definitions/models.Response' + $ref: '#/definitions/app.Response' security: - "": [] summary: 角色列表数据 @@ -1585,29 +1616,6 @@ paths: summary: RoleMenu列表数据 tags: - 角色菜单 - post: - consumes: - - application/x-www-form-urlencoded - description: 获取JSON - parameters: - - description: role_id - in: formData - name: role_id - required: true - type: string - - description: menu_id - in: formData - name: menu_id - required: true - type: string - responses: - "200": - description: '{"code": -1, "message": "添加失败"}' - schema: - type: string - summary: 创建角色菜单 - tags: - - 角色菜单 /api/v1/rolemenu/{id}: delete: description: 删除数据 @@ -1629,6 +1637,107 @@ paths: summary: 删除用户菜单数据 tags: - 角色菜单 + /api/v1/sys/tables/info: + post: + consumes: + - application/json + description: 添加表结构 + parameters: + - description: tableName / 数据表名称 + in: query + name: tables + type: string + responses: + "200": + description: '{"code": -1, "message": "添加失败"}' + schema: + type: string + security: + - Bearer: [] + summary: 添加表结构 + tags: + - 工具 - 生成表 + put: + consumes: + - application/json + description: 修改表结构 + parameters: + - description: body + in: body + name: data + required: true + schema: + $ref: '#/definitions/models.Dept' + type: object + responses: + "200": + description: '{"code": -1, "message": "添加失败"}' + schema: + type: string + security: + - Bearer: [] + summary: 修改表结构 + tags: + - 工具 - 生成表 + /api/v1/sys/tables/info/{tableId}: + delete: + description: 删除表结构 + parameters: + - description: tableId + in: path + name: tableId + required: true + type: integer + responses: + "200": + description: '{"code": -1, "message": "删除失败"}' + schema: + type: string + summary: 删除表结构 + tags: + - 工具 - 生成表 + get: + description: 获取JSON + parameters: + - description: configKey + in: path + name: configKey + required: true + type: integer + responses: + "200": + description: '{"code": 200, "data": [...]}' + schema: + $ref: '#/definitions/app.Response' + security: + - "": [] + summary: 获取配置 + tags: + - 工具 - 生成表 + /api/v1/sys/tables/page: + get: + description: 生成表分页列表 + parameters: + - description: tableName / 数据表名称 + in: query + name: tableName + type: string + - description: pageSize / 页条数 + in: query + name: pageSize + type: integer + - description: pageIndex / 页码 + in: query + name: pageIndex + type: integer + responses: + "200": + description: '{"code": 200, "data": [...]}' + schema: + $ref: '#/definitions/app.Response' + summary: 分页列表数据 + tags: + - 工具 - 生成表 /api/v1/sysUser: get: description: 获取JSON @@ -1636,7 +1745,7 @@ paths: "200": description: '{"code": 200, "data": [...]}' schema: - $ref: '#/definitions/models.Response' + $ref: '#/definitions/app.Response' security: - "": [] summary: 获取用户角色和职位 @@ -1675,7 +1784,7 @@ paths: "200": description: '{"code": 200, "data": [...]}' schema: - $ref: '#/definitions/models.Response' + $ref: '#/definitions/app.Response' security: - "": [] summary: 获取用户 @@ -1736,30 +1845,6 @@ paths: summary: 修改用户数据 tags: - 用户 - /api/v1/tables/page: - get: - description: 数据库表分页列表 / database table page list - parameters: - - description: tableName / 数据表名称 - in: query - name: tableName - type: string - - description: pageSize / 页条数 - in: query - name: pageSize - type: integer - - description: pageIndex / 页码 - in: query - name: pageIndex - type: integer - responses: - "200": - description: '{"code": 200, "data": [...]}' - schema: - $ref: '#/definitions/models.Response' - summary: 分页列表数据 / page list data - tags: - - 工具 / Tools /api/v1/user/profile: get: description: 获取JSON @@ -1767,7 +1852,7 @@ paths: "200": description: '{"code": 200, "data": [...]}' schema: - $ref: '#/definitions/models.Response' + $ref: '#/definitions/app.Response' security: - "": [] summary: 获取当前登录用户 @@ -1835,15 +1920,7 @@ paths: - text/html responses: "200": - description: 'OK - Load average: 2.39, 2.13, 1.97 | Cores: 2' - schema: - type: string - "429": - description: WARNING - schema: - type: string - "500": - description: CRITICAL + description: OK schema: type: string summary: CPU 使用量 @@ -1890,15 +1967,7 @@ paths: - text/html responses: "200": - description: 'OK - Free space: 455MB (0GB) / 8192MB (8GB) | Used: 5%' - schema: - type: string - "429": - description: WARNING - schema: - type: string - "500": - description: CRITICAL + description: OK schema: type: string summary: OS @@ -1911,15 +1980,7 @@ paths: - text/html responses: "200": - description: 'OK - Free space: 455MB (0GB) / 8192MB (8GB) | Used: 5%' - schema: - type: string - "429": - description: WARNING - schema: - type: string - "500": - description: CRITICAL + description: OK schema: type: string summary: 内存使用量 diff --git a/go.mod b/go.mod index 4af0d03c..74922516 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,6 @@ require ( github.com/go-ole/go-ole v1.2.4 // indirect github.com/go-openapi/spec v0.19.7 // indirect github.com/go-openapi/swag v0.19.8 // indirect - github.com/go-redis/redis v6.15.7+incompatible github.com/go-sql-driver/mysql v1.4.1 github.com/golang/protobuf v1.3.2 // indirect github.com/google/uuid v1.1.1 @@ -21,12 +20,15 @@ require ( github.com/json-iterator/go v1.1.8 // indirect github.com/mailru/easyjson v0.7.1 // indirect github.com/mattn/go-isatty v0.0.10 // indirect + github.com/mitchellh/go-homedir v1.1.0 github.com/mojocn/base64Captcha v1.3.1 github.com/mssola/user_agent v0.5.1 github.com/robfig/cron/v3 v3.0.0 github.com/satori/go.uuid v1.2.0 github.com/shirou/gopsutil v2.20.3+incompatible github.com/sirupsen/logrus v1.2.0 + github.com/spf13/cobra v1.0.0 + github.com/spf13/pflag v1.0.3 github.com/spf13/viper v1.6.2 github.com/swaggo/gin-swagger v1.2.0 github.com/swaggo/swag v1.6.5 diff --git a/go.sum b/go.sum index 803f097d..1fecdc3d 100644 --- a/go.sum +++ b/go.sum @@ -41,6 +41,7 @@ github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3Ee github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -101,8 +102,6 @@ github.com/go-openapi/swag v0.19.5 h1:lTz6Ys4CmqqCQmZPBlbQENR1/GucA2bzYTE12Pw4tF github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= github.com/go-openapi/swag v0.19.8 h1:vfK6jLhs7OI4tAXkvkooviaE1JEPcw3mutyegLHHjmk= github.com/go-openapi/swag v0.19.8/go.mod h1:ao+8BpOPyKdpQz3AOJfbeEVpLmWAvlT1IfTe5McPyhY= -github.com/go-redis/redis v6.15.7+incompatible h1:3skhDh95XQMpnqeqNftPkQD9jL9e5e36z/1SUm6dy1U= -github.com/go-redis/redis v6.15.7+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA= github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA= github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= @@ -145,6 +144,8 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/jinzhu/gorm v1.9.10 h1:HvrsqdhCW78xpJF67g1hMxS6eCToo9PZH4LDB8WKPac= github.com/jinzhu/gorm v1.9.10/go.mod h1:Kh6hTsSGffh4ui079FHrR5Gg+5D0hgihqDcsDN2BBJY= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= @@ -175,6 +176,7 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/lib/pq v1.1.1 h1:sJZmqHoEaY7f+NPP8pgLB/WxulyR3fewgCM2qaSlBb4= github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= +github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329 h1:2gxZ0XQIU/5z3Z3bUBu+FXuk2pFbkN6tcwi/pjyaDic= @@ -194,6 +196,8 @@ github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcME github.com/mattn/go-sqlite3 v1.10.0 h1:jbhqpg7tQe4SupckyijYiy0mJJ/pRyHvXf7JdWK860o= github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -257,10 +261,13 @@ github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8= github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cobra v1.0.0 h1:6m/oheQuQ13N9ks4hubMG6BnvwOeaJrqSPLahSnczz8= +github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE= github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk= github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE= github.com/spf13/viper v1.6.2 h1:7aKfF+e8/k68gda3LOjo5RxiUqddoFxVq4BKBPrxk5E= github.com/spf13/viper v1.6.2/go.mod h1:t3iDnF5Jlj76alVNuyFBk5oUMCvsrkbvZK0WQdfDi5k= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/handler/auth.go b/handler/auth.go index b5804ca6..ade8f7a8 100644 --- a/handler/auth.go +++ b/handler/auth.go @@ -6,7 +6,7 @@ import ( "github.com/mssola/user_agent" "go-admin/models" jwt "go-admin/pkg/jwtauth" - "go-admin/pkg/utils" + "go-admin/tools" "log" "net/http" ) @@ -57,9 +57,9 @@ func Authenticator(c *gin.Context) (interface{}, error) { ua := user_agent.New(c.Request.UserAgent()) loginlog.Ipaddr = c.ClientIP() - location := utils.GetLocation(c.ClientIP()) + location := tools.GetLocation(c.ClientIP()) loginlog.LoginLocation = location - loginlog.LoginTime = utils.GetCurrntTime() + loginlog.LoginTime = tools.GetCurrntTime() loginlog.Status = "0" loginlog.Remark = c.Request.UserAgent() browserName, browserVersion := ua.Browser() @@ -110,16 +110,16 @@ func LogOut(c *gin.Context) { var loginlog models.LoginLog ua := user_agent.New(c.Request.UserAgent()) loginlog.Ipaddr = c.ClientIP() - location := utils.GetLocation(c.ClientIP()) + location := tools.GetLocation(c.ClientIP()) loginlog.LoginLocation = location - loginlog.LoginTime = utils.GetCurrntTime() + loginlog.LoginTime = tools.GetCurrntTime() loginlog.Status = "0" loginlog.Remark = c.Request.UserAgent() browserName, browserVersion := ua.Browser() loginlog.Browser = browserName + " " + browserVersion loginlog.Os = ua.OS() loginlog.Platform = ua.Platform() - loginlog.Username = utils.GetUserName(c) + loginlog.Username = tools.GetUserName(c) loginlog.Msg = "退出成功" loginlog.Create() c.JSON(http.StatusOK, gin.H{ diff --git a/handler/goadmin.go b/handler/goadmin.go new file mode 100644 index 00000000..f2c830e7 --- /dev/null +++ b/handler/goadmin.go @@ -0,0 +1,10 @@ +package handler + +import ( + "github.com/gin-gonic/gin" + "go-admin/tools/app" +) + +func HelloGoAdmin(c *gin.Context) { + app.OK(c,"欢迎使用go-admin 中后台脚手架","") +} \ No newline at end of file diff --git a/handler/sd/check.go b/handler/sd/check.go index 705228f1..9554b504 100644 --- a/handler/sd/check.go +++ b/handler/sd/check.go @@ -7,7 +7,7 @@ import ( "github.com/shirou/gopsutil/disk" "github.com/shirou/gopsutil/load" "github.com/shirou/gopsutil/mem" - "go-admin/pkg/app" + "go-admin/tools/app" "net/http" "runtime" "time" diff --git a/main.go b/main.go index dc6762f4..b6bc81e7 100644 --- a/main.go +++ b/main.go @@ -1,18 +1,7 @@ package main import ( - "context" - "github.com/gin-gonic/gin" - "go-admin/config" - orm "go-admin/database" - "go-admin/models" - "go-admin/models/gorm" - "go-admin/router" - "log" - "net/http" - "os" - "os/signal" - "time" + "go-admin/cmd" ) // @title go-admin API @@ -26,54 +15,59 @@ import ( // @in header // @name Authorization +//func main() { +// configName := "settings" +// +// +// config.InitConfig(configName) +// +// gin.SetMode(gin.DebugMode) +// log.Println(config.DatabaseConfig.Port) +// +// err := gorm.AutoMigrate(orm.Eloquent) +// if err != nil { +// log.Fatalln("数据库初始化失败 err: %v", err) +// } +// +// if config.ApplicationConfig.IsInit { +// if err := models.InitDb(); err != nil { +// log.Fatal("数据库基础数据初始化失败!") +// } else { +// config.SetApplicationIsInit() +// } +// } +// +// r := router.InitRouter() +// +// defer orm.Eloquent.Close() +// +// srv := &http.Server{ +// Addr: config.ApplicationConfig.Host + ":" + config.ApplicationConfig.Port, +// Handler: r, +// } +// +// go func() { +// // 服务连接 +// if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed { +// log.Fatalf("listen: %s\n", err) +// } +// }() +// log.Println("Server Run ", config.ApplicationConfig.Host+":"+config.ApplicationConfig.Port) +// log.Println("Enter Control + C Shutdown Server") +// // 等待中断信号以优雅地关闭服务器(设置 5 秒的超时时间) +// quit := make(chan os.Signal) +// signal.Notify(quit, os.Interrupt) +// <-quit +// log.Println("Shutdown Server ...") +// +// ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) +// defer cancel() +// if err := srv.Shutdown(ctx); err != nil { +// log.Fatal("Server Shutdown:", err) +// } +// log.Println("Server exiting") +//} + func main() { - - gin.SetMode(gin.DebugMode) - log.Println(config.DatabaseConfig.Port) - - err := gorm.AutoMigrate(orm.Eloquent) - if err != nil { - log.Fatalln("数据库初始化失败 err: %v", err) - } - - if config.ApplicationConfig.IsInit { - if err := models.InitDb(); err != nil { - log.Fatal("数据库基础数据初始化失败!") - } else { - config.SetApplicationIsInit() - } - } - - r := router.InitRouter() - - defer orm.Eloquent.Close() - //if err := r.Run(config.ApplicationConfig.Host + ":" + config.ApplicationConfig.Port); err != nil { - // log.Fatal(err) - //} - - srv := &http.Server{ - Addr: config.ApplicationConfig.Host + ":" + config.ApplicationConfig.Port, - Handler: r, - } - - go func() { - // 服务连接 - if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed { - log.Fatalf("listen: %s\n", err) - } - }() - log.Println("Server Run ", config.ApplicationConfig.Host+":"+config.ApplicationConfig.Port) - log.Println("Enter Control + C Shutdown Server") - // 等待中断信号以优雅地关闭服务器(设置 5 秒的超时时间) - quit := make(chan os.Signal) - signal.Notify(quit, os.Interrupt) - <-quit - log.Println("Shutdown Server ...") - - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - defer cancel() - if err := srv.Shutdown(ctx); err != nil { - log.Fatal("Server Shutdown:", err) - } - log.Println("Server exiting") + cmd.Execute() } diff --git a/middleware/auth.go b/middleware/auth.go index aa7fc029..a7944fc9 100644 --- a/middleware/auth.go +++ b/middleware/auth.go @@ -1,9 +1,9 @@ package middleware import ( - config2 "go-admin/config" "go-admin/handler" jwt "go-admin/pkg/jwtauth" + "go-admin/tools/config" "time" ) @@ -13,7 +13,7 @@ func AuthInit() (*jwt.GinJWTMiddleware, error) { Key: []byte("secret key"), Timeout: time.Hour, MaxRefresh: time.Hour, - IdentityKey: config2.ApplicationConfig.JwtSecret, + IdentityKey: config.ApplicationConfig.JwtSecret, PayloadFunc: handler.PayloadFunc, IdentityHandler: handler.IdentityHandler, Authenticator: handler.Authenticator, diff --git a/middleware/demo.go b/middleware/demo.go index 0448f725..00954dcd 100644 --- a/middleware/demo.go +++ b/middleware/demo.go @@ -2,20 +2,20 @@ package middleware import ( "github.com/gin-gonic/gin" - "go-admin/config" + config2 "go-admin/tools/config" "net/http" ) func DemoEvn() gin.HandlerFunc { return func(c *gin.Context) { - if config.ApplicationConfig.Env == "demo" { + if config2.ApplicationConfig.Mode == "demo" { method := c.Request.Method if method == "GET" || method == "OPTIONS" || c.Request.RequestURI == "/login" || c.Request.RequestURI == "/api/v1/logout" { c.Next() } else { c.JSON(http.StatusOK, gin.H{ "code": 500, - "msg": config.ApplicationConfig.EnvMsg, + "msg": config2.ApplicationConfig.DemoMsg, }) c.Abort() return diff --git a/middleware/logger.go b/middleware/logger.go index f0c1ba20..fc2f0b07 100644 --- a/middleware/logger.go +++ b/middleware/logger.go @@ -1,13 +1,10 @@ package middleware import ( - "fmt" "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" - "go-admin/config" "go-admin/models" - "go-admin/pkg/utils" - "os" + "go-admin/tools" "strings" "time" ) @@ -18,21 +15,6 @@ var logger = logrus.New() // 日志记录到文件 func LoggerToFile() gin.HandlerFunc { - //写入文件 - src, err := os.OpenFile(config.ApplicationConfig.LogPath, os.O_APPEND|os.O_WRONLY, os.ModeAppend) - if err != nil { - fmt.Println("err", err) - } - - //设置输出 - logger.Out = src - - //设置日志级别 - logger.SetLevel(logrus.DebugLevel) - - //设置日志格式 - logger.SetFormatter(&logrus.TextFormatter{}) - return func(c *gin.Context) { // 开始时间 startTime := time.Now() @@ -59,24 +41,16 @@ func LoggerToFile() gin.HandlerFunc { clientIP := c.ClientIP() // 日志格式 - logger.Infof(" %3d %13v %15s %s %s \r\n", + logger.Infof("%s [%s] %3d %13v %15s %s %s \r\n", + startTime.Format("2006-01-02 15:04:05.9999"), + strings.ToUpper(logger.Level.String()), statusCode, latencyTime, clientIP, reqMethod, reqUri, ) - logger.Infoln("-") - fmt.Println( - startTime.Format("\n2006-01-02 15:04:05.9999"), - "[INFO]", - reqMethod, - reqUri, - statusCode, - latencyTime, - reqUri, - clientIP, - ) + if c.Request.Method != "GET" && c.Request.Method != "OPTIONS" { menu := models.Menu{} menu.Path = reqUri @@ -84,9 +58,9 @@ func LoggerToFile() gin.HandlerFunc { menuList, _ := menu.Get() sysOperLog := models.SysOperLog{} sysOperLog.OperIp = clientIP - sysOperLog.OperLocation = utils.GetLocation(clientIP) - sysOperLog.Status = utils.IntToString(statusCode) - sysOperLog.OperName = utils.GetUserName(c) + sysOperLog.OperLocation = tools.GetLocation(clientIP) + sysOperLog.Status = tools.IntToString(statusCode) + sysOperLog.OperName = tools.GetUserName(c) sysOperLog.RequestMethod = c.Request.Method sysOperLog.OperUrl = reqUri if reqUri == "/login" { @@ -112,9 +86,9 @@ func LoggerToFile() gin.HandlerFunc { sysOperLog.Title = menuList[0].Title } b, _ := c.Get("body") - sysOperLog.OperParam, _ = utils.StructToJsonStr(b) - sysOperLog.CreateBy = utils.GetUserName(c) - sysOperLog.OperTime = utils.GetCurrntTime() + sysOperLog.OperParam, _ = tools.StructToJsonStr(b) + sysOperLog.CreateBy = tools.GetUserName(c) + sysOperLog.OperTime = tools.GetCurrntTime() sysOperLog.LatencyTime = (latencyTime).String() sysOperLog.UserAgent = c.Request.UserAgent() if c.Err() == nil { diff --git a/middleware/permission.go b/middleware/permission.go index e8094550..5edf6524 100644 --- a/middleware/permission.go +++ b/middleware/permission.go @@ -2,10 +2,10 @@ package middleware import ( "github.com/gin-gonic/gin" - "go-admin/pkg" mycasbin "go-admin/pkg/casbin" "go-admin/pkg/jwtauth" _ "go-admin/pkg/jwtauth" + "go-admin/tools" "log" "net/http" ) @@ -16,19 +16,19 @@ func AuthCheckRole() gin.HandlerFunc { data, _ := c.Get("JWT_PAYLOAD") v := data.(jwtauth.MapClaims) e, err := mycasbin.Casbin() - pkg.HasError(err,"",500) + tools.HasError(err, "", 500) //检查权限 res, err := e.Enforce(v["rolekey"], c.Request.URL.Path, c.Request.Method) log.Println("----------------", v["rolekey"], c.Request.URL.Path, c.Request.Method) - pkg.HasError(err,"",500) + tools.HasError(err, "", 500) if res { c.Next() } else { c.JSON(http.StatusOK, gin.H{ - "status": 401, - "msg": "对不起,您没有该接口访问权限,请联系管理员", + "code": 401, + "msg": "对不起,您没有该接口访问权限,请联系管理员", }) c.Abort() return diff --git a/models/config.go b/models/config.go index 68c42ab2..cb8a19ba 100644 --- a/models/config.go +++ b/models/config.go @@ -2,7 +2,8 @@ package models import ( orm "go-admin/database" - "go-admin/pkg/utils" + "go-admin/tools" + _ "time" ) type SysConfig struct { @@ -71,7 +72,7 @@ func (e *SysConfig) GetPage(pageSize int, pageIndex int) ([]SysConfig, int, erro // 数据权限控制 dataPermission := new(DataPermission) - dataPermission.UserId, _ = utils.StringToInt(e.DataScope) + dataPermission.UserId, _ = tools.StringToInt(e.DataScope) table = dataPermission.GetDataScope("sys_config", table) var count int diff --git a/models/datascope.go b/models/datascope.go index 2202e119..6bc0da64 100644 --- a/models/datascope.go +++ b/models/datascope.go @@ -2,7 +2,7 @@ package models import ( "github.com/jinzhu/gorm" - "go-admin/pkg/utils" + "go-admin/tools" ) type DataPermission struct { @@ -27,7 +27,7 @@ func (e *DataPermission) GetDataScope(tbname string, table *gorm.DB) *gorm.DB { table = table.Where(tbname+".create_by in (SELECT user_id from sys_user where dept_id = ? )", user.DeptId) } if role.DataScope == "4" { - table = table.Where(tbname+".create_by in (SELECT user_id from sys_user where sys_user.dept_id in(select dept_id from sys_dept where dept_path like ? ))", "%"+utils.IntToString(user.DeptId)+"%") + table = table.Where(tbname+".create_by in (SELECT user_id from sys_user where sys_user.dept_id in(select dept_id from sys_dept where dept_path like ? ))", "%"+tools.IntToString(user.DeptId)+"%") } if role.DataScope == "5" || role.DataScope == "" { table = table.Where(tbname+".create_by = ?", e.UserId) diff --git a/models/dept.go b/models/dept.go index a7d4e7f7..a679fe94 100644 --- a/models/dept.go +++ b/models/dept.go @@ -2,7 +2,8 @@ package models import ( orm "go-admin/database" - "go-admin/pkg/utils" + "go-admin/tools" + _ "time" ) type Dept struct { @@ -40,7 +41,7 @@ func (e *Dept) Create() (Dept, error) { err := result.Error return doc, err } - deptPath := "/" + utils.IntToString(e.DeptId) + deptPath := "/" + tools.IntToString(e.DeptId) if int(e.ParentId) != 0 { var deptP Dept orm.Eloquent.Table(e.TableName()).Where("dept_id = ?", e.ParentId).First(&deptP) @@ -115,7 +116,7 @@ func (e *Dept) GetPage(bl bool) ([]Dept, error) { if bl { // 数据权限控制 dataPermission := new(DataPermission) - dataPermission.UserId, _ = utils.StringToInt(e.DataScope) + dataPermission.UserId, _ = tools.StringToInt(e.DataScope) table = dataPermission.GetDataScope("sys_dept", table) } @@ -173,7 +174,7 @@ func (e *Dept) Update(id int) (update Dept, err error) { return } - deptPath := "/" + utils.IntToString(e.DeptId) + deptPath := "/" + tools.IntToString(e.DeptId) if int(e.ParentId) != 0 { var deptP Dept orm.Eloquent.Table(e.TableName()).Where("dept_id = ?", e.ParentId).First(&deptP) diff --git a/models/dictData.go b/models/dictData.go index 9bae03fe..16b8be4d 100644 --- a/models/dictData.go +++ b/models/dictData.go @@ -2,7 +2,7 @@ package models import ( orm "go-admin/database" - "go-admin/pkg/utils" + "go-admin/tools" ) type DictData struct { @@ -98,7 +98,7 @@ func (e *DictData) GetPage(pageSize int, pageIndex int) ([]DictData, int, error) // 数据权限控制 dataPermission := new(DataPermission) - dataPermission.UserId, _ = utils.StringToInt(e.DataScope) + dataPermission.UserId, _ = tools.StringToInt(e.DataScope) table = dataPermission.GetDataScope("sys_dict_data", table) var count int diff --git a/models/dictType.go b/models/dictType.go index 3f72c762..7235fa06 100644 --- a/models/dictType.go +++ b/models/dictType.go @@ -2,7 +2,7 @@ package models import ( orm "go-admin/database" - "go-admin/pkg/utils" + "go-admin/tools" ) type DictType struct { @@ -86,7 +86,7 @@ func (e *DictType) GetPage(pageSize int, pageIndex int) ([]DictType, int, error) // 数据权限控制 dataPermission := new(DataPermission) - dataPermission.UserId, _ = utils.StringToInt(e.DataScope) + dataPermission.UserId, _ = tools.StringToInt(e.DataScope) table = dataPermission.GetDataScope("sys_dict_type", table) var count int diff --git a/models/gorm/gorm.go b/models/gorm/gorm.go index c9210176..d0b3da39 100644 --- a/models/gorm/gorm.go +++ b/models/gorm/gorm.go @@ -2,13 +2,13 @@ package gorm import ( "github.com/jinzhu/gorm" - "go-admin/config" "go-admin/models" "go-admin/models/tools" + config2 "go-admin/tools/config" ) func AutoMigrate(db *gorm.DB) error { - if config.DatabaseConfig.Dbtype == "mysql" { + if config2.DatabaseConfig.Dbtype == "mysql" { db = db.Set("gorm:table_options", "ENGINE=InnoDB CHARSET=utf8mb4") } db.SingularTable(true) diff --git a/models/initdb.go b/models/initdb.go index d144b0e2..d17f10e6 100644 --- a/models/initdb.go +++ b/models/initdb.go @@ -2,15 +2,15 @@ package models import ( "fmt" - "go-admin/config" orm "go-admin/database" + config2 "go-admin/tools/config" "io/ioutil" "strings" ) func InitDb() error { filePath := "config/db.sql" - if config.DatabaseConfig.Dbtype == "sqlite3" { + if config2.DatabaseConfig.Dbtype == "sqlite3" { fmt.Println("sqlite3数据库无需初始化!") return nil } diff --git a/models/login.go b/models/login.go index 9c207cfa..75860b74 100644 --- a/models/login.go +++ b/models/login.go @@ -2,7 +2,7 @@ package models import ( orm "go-admin/database" - "go-admin/pkg" + "go-admin/tools" "log" "strings" ) @@ -19,15 +19,15 @@ func (u *Login) GetUser() (user SysUser, role SysRole, e error) { e = orm.Eloquent.Table("sys_user").Where("username = ? ", u.Username).Find(&user).Error if e != nil { if strings.Contains(e.Error(), "record not found") { - pkg.HasError(e, "账号或密码错误(代码204)", 500) + tools.HasError(e, "账号或密码错误(代码204)", 500) } log.Print(e) return } - _, e = pkg.CompareHashAndPassword(user.Password, u.Password) + _, e = tools.CompareHashAndPassword(user.Password, u.Password) if e != nil { if strings.Contains(e.Error(), "hashedPassword is not the hash of the given password") { - pkg.HasError(e, "账号或密码错误(代码201)", 500) + tools.HasError(e, "账号或密码错误(代码201)", 500) } log.Print(e) return diff --git a/models/menu.go b/models/menu.go index ef9ea875..e88ee198 100644 --- a/models/menu.go +++ b/models/menu.go @@ -3,7 +3,7 @@ package models import ( "errors" orm "go-admin/database" - "go-admin/pkg/utils" + "go-admin/tools" ) type Menu struct { @@ -248,13 +248,19 @@ func (e *Menu) GetPage() (Menus []Menu, err error) { if e.MenuName != "" { table = table.Where("menu_name = ?", e.MenuName) } + if e.Title != "" { + table = table.Where("title = ?", e.Title) + } + if e.Visible != "" { + table = table.Where("visible = ?", e.Visible) + } if e.MenuType != "" { table = table.Where("menu_type = ?", e.MenuType) } // 数据权限控制 dataPermission := new(DataPermission) - dataPermission.UserId, _ = utils.StringToInt(e.DataScope) + dataPermission.UserId, _ = tools.StringToInt(e.DataScope) table = dataPermission.GetDataScope("sys_menu", table) if err = table.Order("sort").Find(&Menus).Error; err != nil { @@ -285,9 +291,9 @@ func InitPaths(menu *Menu) (err error) { err = errors.New("父级paths异常,请尝试对当前节点父级菜单进行更新操作!") return } - menu.Paths = parentMenu.Paths + "/" + utils.IntToString(menu.MenuId) + menu.Paths = parentMenu.Paths + "/" + tools.IntToString(menu.MenuId) } else { - menu.Paths = "/0/" + utils.IntToString(menu.MenuId) + menu.Paths = "/0/" + tools.IntToString(menu.MenuId) } orm.Eloquent.Table("sys_menu").Where("menu_id = ?", menu.MenuId).Update("paths", menu.Paths) return diff --git a/models/post.go b/models/post.go index 63dbb876..68fa276a 100644 --- a/models/post.go +++ b/models/post.go @@ -2,7 +2,7 @@ package models import ( orm "go-admin/database" - "go-admin/pkg/utils" + "go-admin/tools" ) type Post struct { @@ -96,7 +96,7 @@ func (e *Post) GetPage(pageSize int, pageIndex int) ([]Post, int, error) { // 数据权限控制 dataPermission := new(DataPermission) - dataPermission.UserId, _ = utils.StringToInt(e.DataScope) + dataPermission.UserId, _ = tools.StringToInt(e.DataScope) table = dataPermission.GetDataScope("sys_post", table) var count int diff --git a/models/role.go b/models/role.go index 2c5b232c..9860fe9d 100644 --- a/models/role.go +++ b/models/role.go @@ -2,7 +2,7 @@ package models import ( orm "go-admin/database" - "go-admin/pkg/utils" + "go-admin/tools" ) type SysRole struct { @@ -50,7 +50,7 @@ func (e *SysRole) GetPage(pageSize int, pageIndex int) ([]SysRole, int, error) { // 数据权限控制 dataPermission := new(DataPermission) - dataPermission.UserId, _ = utils.StringToInt(e.DataScope) + dataPermission.UserId, _ = tools.StringToInt(e.DataScope) table = dataPermission.GetDataScope("sys_role", table) var count int diff --git a/models/roledept.go b/models/roledept.go index cdcc202c..3c00da39 100644 --- a/models/roledept.go +++ b/models/roledept.go @@ -37,7 +37,7 @@ func (rm *SysRoleDept) DeleteRoleDept(roleId int) (bool, error) { return false, err } var role SysRole - if err := orm.Eloquent.Table("sys_role").Where("id = ?", roleId).First(&role).Error; err != nil { + if err := orm.Eloquent.Table("sys_role").Where("role_id = ?", roleId).First(&role).Error; err != nil { return false, err } diff --git a/models/rolemenu.go b/models/rolemenu.go index 36bb5321..66fb4e9d 100644 --- a/models/rolemenu.go +++ b/models/rolemenu.go @@ -3,7 +3,7 @@ package models import ( "fmt" orm "go-admin/database" - "go-admin/pkg/utils" + "go-admin/tools" ) type RoleMenu struct { @@ -134,7 +134,7 @@ func (rm *RoleMenu) Insert(roleId int, menuId []int) (bool, error) { } func (rm *RoleMenu) Delete(RoleId string, MenuID string) (bool, error) { - rm.RoleId, _ = utils.StringToInt(RoleId) + rm.RoleId, _ = tools.StringToInt(RoleId) table := orm.Eloquent.Table("sys_role_menu").Where("role_id = ?", RoleId) if MenuID != "" { table = table.Where("menu_id = ?", MenuID) diff --git a/models/sysuser.go b/models/sysuser.go index fc851b61..86ab2c63 100644 --- a/models/sysuser.go +++ b/models/sysuser.go @@ -3,12 +3,10 @@ package models import ( "errors" orm "go-admin/database" - "go-admin/pkg" - "go-admin/pkg/utils" + "go-admin/tools" + "golang.org/x/crypto/bcrypt" "log" "strings" - - "golang.org/x/crypto/bcrypt" ) // User @@ -127,21 +125,27 @@ func (e *SysUser) Get() (SysUserView SysUserView, err error) { func (e *SysUser) GetPage(pageSize int, pageIndex int) ([]SysUserPage, int, error) { var doc []SysUserPage - table := orm.Eloquent.Select("sys_user.*,sys_dept.dept_name").Table(e.TableName()) table = table.Joins("left join sys_dept on sys_dept.dept_id = sys_user.dept_id") if e.Username != "" { table = table.Where("username = ?", e.Username) } + if e.Status != "" { + table = table.Where("sys_user.status = ?", e.Status) + } + + if e.Phone != "" { + table = table.Where("sys_user.phone = ?", e.Phone) + } if e.DeptId != 0 { - table = table.Where("sys_user.dept_id in (select dept_id from sys_dept where dept_path like ? )", "%"+utils.IntToString(e.DeptId)+"%") + table = table.Where("sys_user.dept_id in (select dept_id from sys_dept where dept_path like ? )", "%"+tools.IntToString(e.DeptId)+"%") } // 数据权限控制 dataPermission := new(DataPermission) - dataPermission.UserId, _ = utils.StringToInt(e.DataScope) + dataPermission.UserId, _ = tools.StringToInt(e.DataScope) table = dataPermission.GetDataScope("sys_user", table) var count int @@ -221,16 +225,16 @@ func (e *SysUser) BatchDelete(id []int) (Result bool, err error) { func (e *SysUser) SetPwd(pwd SysUserPwd) (Result bool, err error) { user, _ := e.Get() - _, err = pkg.CompareHashAndPassword(user.Password, pwd.OldPassword) + _, err = tools.CompareHashAndPassword(user.Password, pwd.OldPassword) if err != nil { if strings.Contains(err.Error(), "hashedPassword is not the hash of the given password") { - pkg.HasError(err, "密码错误(代码202)", 500) + tools.HasError(err, "密码错误(代码202)", 500) } log.Print(err) return } e.Password = pwd.NewPassword _, err = e.Update(e.UserId) - pkg.HasError(err, "更新密码失败(代码202)", 500) + tools.HasError(err, "更新密码失败(代码202)", 500) return } diff --git a/models/tools/dbcolumns.go b/models/tools/dbcolumns.go index e5f8cf29..aae9f50d 100644 --- a/models/tools/dbcolumns.go +++ b/models/tools/dbcolumns.go @@ -2,8 +2,8 @@ package tools import ( "errors" - "go-admin/config" orm "go-admin/database" + config2 "go-admin/tools/config" ) type DBColumns struct { @@ -25,7 +25,7 @@ func (e *DBColumns) GetPage(pageSize int, pageIndex int) ([]DBColumns, int, erro var doc []DBColumns table := orm.Eloquent.Select("*").Table("information_schema.`COLUMNS`") - table = table.Where("table_schema= ? ", config.DatabaseConfig.Database) + table = table.Where("table_schema= ? ", config2.DatabaseConfig.Name) if e.TableName != "" { return nil, 0, errors.New("table name cannot be empty!") @@ -46,7 +46,7 @@ func (e *DBColumns) GetList() ([]DBColumns, error) { var doc []DBColumns table := orm.Eloquent.Select("*").Table("information_schema.columns") - table = table.Where("table_schema= ? ", config.DatabaseConfig.Database) + table = table.Where("table_schema= ? ", config2.DatabaseConfig.Name) if e.TableName == "" { return nil, errors.New("table name cannot be empty!") diff --git a/models/tools/dbtables.go b/models/tools/dbtables.go index 46df8675..08229f32 100644 --- a/models/tools/dbtables.go +++ b/models/tools/dbtables.go @@ -2,8 +2,8 @@ package tools import ( "errors" - "go-admin/config" orm "go-admin/database" + config2 "go-admin/tools/config" ) type DBTables struct { @@ -20,7 +20,7 @@ func (e *DBTables) GetPage(pageSize int, pageIndex int) ([]DBTables, int, error) var doc []DBTables table := orm.Eloquent.Select("*").Table("information_schema.tables") - table = table.Where("table_schema= ? ", config.DatabaseConfig.Database) + table = table.Where("table_schema= ? ", config2.DatabaseConfig.Name) if e.TableName != "" { table = table.Where("TABLE_NAME = ?", e.TableName) @@ -39,7 +39,7 @@ func (e *DBTables) Get() (DBTables, error) { var doc DBTables table := orm.Eloquent.Select("*").Table("information_schema.tables") - table = table.Where("table_schema= ? ", config.DatabaseConfig.Database) + table = table.Where("table_schema= ? ", config2.DatabaseConfig.Name) if e.TableName == "" { return doc, errors.New("table name cannot be empty!") } diff --git a/models/tools/systables.go b/models/tools/systables.go index d5b29a01..78025bce 100644 --- a/models/tools/systables.go +++ b/models/tools/systables.go @@ -6,15 +6,15 @@ import ( ) type SysTables struct { - TableId int `gorm:"primary_key;auto_increment" json:"tableId"` //表编码 - TableName string `gorm:"type:varchar(255);" json:"tableName"` //表名称 - TableComment string `gorm:"type:varchar(255);" json:"tableComment"` //表备注 - ClassName string `gorm:"type:varchar(255);" json:"className"` //类名 + TableId int `gorm:"primary_key;auto_increment" json:"tableId"` //表编码 + TBName string `gorm:"column:table_name;type:varchar(255);" json:"tableName"` //表名称 + TableComment string `gorm:"type:varchar(255);" json:"tableComment"` //表备注 + ClassName string `gorm:"type:varchar(255);" json:"className"` //类名 TplCategory string `gorm:"type:varchar(255);" json:"tplCategory"` PackageName string `gorm:"type:varchar(255);" json:"packageName"` //包名 - ModuleName string `gorm:"type:varchar(255);" json:"moduleName"` //模块名 + ModuleName string `gorm:"type:varchar(255);" json:"moduleName"` //模块名 BusinessName string `gorm:"type:varchar(255);" json:"businessName"` - FunctionName string `gorm:"type:varchar(255);" json:"functionName"` //功能名称 + FunctionName string `gorm:"type:varchar(255);" json:"functionName"` //功能名称 FunctionAuthor string `gorm:"type:varchar(255);" json:"functionAuthor"` //功能作者 PkColumn string `gorm:"type:varchar(255);" json:"pkColumn"` PkGoField string `gorm:"type:varchar(255);" json:"pkGoField"` @@ -38,6 +38,10 @@ type SysTables struct { models.BaseModel } +func (SysTables) TableName() string { + return "sys_tables" +} + type Params struct { TreeCode string `gorm:"-" json:"treeCode"` TreeParentCode string `gorm:"-" json:"treeParentCode"` @@ -49,8 +53,8 @@ func (e *SysTables) GetPage(pageSize int, pageIndex int) ([]SysTables, int, erro table := orm.Eloquent.Select("*").Table("sys_tables") - if e.TableName != "" { - table = table.Where("table_name = ?", e.TableName) + if e.TBName != "" { + table = table.Where("table_name = ?", e.TBName) } if e.TableComment != "" { table = table.Where("table_comment = ?", e.TableComment) @@ -70,8 +74,8 @@ func (e *SysTables) Get() (SysTables, error) { var err error table := orm.Eloquent.Select("*").Table("sys_tables") - if e.TableName != "" { - table = table.Where("table_name = ?", e.TableName) + if e.TBName != "" { + table = table.Where("table_name = ?", e.TBName) } if e.TableId != 0 { table = table.Where("table_id = ?", e.TableId) @@ -138,3 +142,11 @@ func (e *SysTables) Delete() (success bool, err error) { success = true return } + +func (e *SysTables) BatchDelete(id []int) (Result bool, err error) { + if err = orm.Eloquent.Table(e.TableName()).Where(" table_id in (?)", id).Delete(&SysColumns{}).Error; err != nil { + return + } + Result = true + return +} diff --git a/pkg/casbin/mycasbin.go b/pkg/casbin/mycasbin.go index 9b3b491a..11aef3ff 100644 --- a/pkg/casbin/mycasbin.go +++ b/pkg/casbin/mycasbin.go @@ -6,14 +6,14 @@ import ( gormadapter "github.com/casbin/gorm-adapter/v2" "github.com/go-kit/kit/endpoint" _ "github.com/go-sql-driver/mysql" - "go-admin/config" - "go-admin/pkg/utils" + "go-admin/database" + "go-admin/tools/config" ) var Em endpoint.Middleware func Casbin() (*casbin.Enforcer, error) { - conn := config.DatabaseConfig.Username + ":" + config.DatabaseConfig.Password + "@tcp(" + config.DatabaseConfig.Host + ":" + utils.IntToString(config.DatabaseConfig.Port) + ")/" + config.DatabaseConfig.Database + conn := database.GetMysqlConnect() if config.DatabaseConfig.Dbtype == "sqlite3" { conn = config.DatabaseConfig.Host } diff --git a/pkg/jwtauth/jwtauth.go b/pkg/jwtauth/jwtauth.go index b38a7997..2649fa66 100644 --- a/pkg/jwtauth/jwtauth.go +++ b/pkg/jwtauth/jwtauth.go @@ -5,7 +5,7 @@ import ( "errors" "github.com/dgrijalva/jwt-go" "github.com/gin-gonic/gin" - "go-admin/config" + config2 "go-admin/tools/config" "io/ioutil" "net/http" "strings" @@ -283,9 +283,9 @@ func (mw *GinJWTMiddleware) MiddlewareInit() error { } mw.Timeout = time.Hour - if config.JwtConfig.Timeout != 0 { + if config2.JwtConfig.Timeout != 0 { // TODO: token过期时长 - mw.Timeout = time.Duration(config.JwtConfig.Timeout) * time.Second + mw.Timeout = time.Duration(config2.JwtConfig.Timeout) * time.Second } if mw.TimeFunc == nil { @@ -391,7 +391,7 @@ func (mw *GinJWTMiddleware) middlewareImpl(c *gin.Context) { return } if int64(claims["exp"].(float64)) < mw.TimeFunc().Unix() { - mw.unauthorized(c, http.StatusUnauthorized, mw.HTTPStatusMessageFunc(ErrExpiredToken, c)) + mw.unauthorized(c, 6401, mw.HTTPStatusMessageFunc(ErrExpiredToken, c)) return } @@ -680,8 +680,6 @@ func (mw *GinJWTMiddleware) ParseToken(c *gin.Context) (*jwt.Token, error) { if mw.usingPublicKeyAlgo() { return mw.pubKey, nil } - - // save token string if vaild c.Set("JWT_TOKEN", token) return mw.Key, nil diff --git a/router/router.go b/router/router.go index 57919161..fcbd4498 100644 --- a/router/router.go +++ b/router/router.go @@ -27,6 +27,7 @@ func InitRouter() *gin.Engine { r.Use(middleware.RequestId()) r.Use(middleware.DemoEvn()) + r.GET("/", system.HelloWorld) r.Static("/static", "./static") r.GET("/info", handler.Ping) @@ -75,6 +76,7 @@ func InitRouter() *gin.Engine { auth := r.Group("/api/v1") auth.Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole()) { + auth.GET("/deptList", system.GetDeptList) auth.GET("/deptTree", system.GetDeptTree) auth.GET("/dept/:deptId", system.GetDept) diff --git a/template/api.go.template b/template/api.go.template index 7e541174..06c39735 100644 --- a/template/api.go.template +++ b/template/api.go.template @@ -4,6 +4,7 @@ import ( "github.com/gin-gonic/gin" "github.com/gin-gonic/gin/binding" "go-admin/models" + "go-admin/tools/app" "go-admin/pkg" "go-admin/utils" "net/http" diff --git a/template/js.go.template b/template/js.go.template new file mode 100644 index 00000000..9c7ca820 --- /dev/null +++ b/template/js.go.template @@ -0,0 +1,46 @@ +import request from '@/utils/request' + +// 查询参数列表 +export function list{{.ClassName}}(query) { +return request({ +url: '/api/v1/{{.ModuleName}}List', +method: 'get', +params: query +}) +} + +// 查询参数详细 +export function get{{.ClassName}} ({{.PkJsonField}}) { +return request({ +url: '/api/v1/{{.ModuleName}}/' + {{.PkJsonField}}, +method: 'get' +}) +} + + +// 新增参数配置 +export function add{{.ClassName}}(data) { +return request({ +url: '/api/v1/{{.ModuleName}}', +method: 'post', +data: data +}) +} + +// 修改参数配置 +export function update{{.ClassName}}(data) { +return request({ +url: '/api/v1/{{.ModuleName}}', +method: 'put', +data: data +}) +} + +// 删除参数配置 +export function del{{.ClassName}}({{.PkJsonField}}) { +return request({ +url: '/api/v1/{{.ModuleName}}/' + {{.PkJsonField}}, +method: 'delete' +}) +} + diff --git a/template/vue.go.template b/template/vue.go.template new file mode 100644 index 00000000..4173b5c2 --- /dev/null +++ b/template/vue.go.template @@ -0,0 +1,271 @@ + + + diff --git a/test/api.go.template b/test/api.go.template index a9595e09..ad50d110 100644 --- a/test/api.go.template +++ b/test/api.go.template @@ -81,7 +81,7 @@ func Get{{.ClassName}}(c *gin.Context) { // @Tags 配置 // @Accept application/json // @Product application/json -// @Param data body models.Config true "data" +// @Param data body models.{{.ClassName}} true "data" // @Success 200 {string} string "{"code": 200, "message": "添加成功"}" // @Success 200 {string} string "{"code": -1, "message": "添加失败"}" // @Router /api/v1/dict/data [post] diff --git a/pkg/app/model.go b/tools/app/model.go similarity index 100% rename from pkg/app/model.go rename to tools/app/model.go diff --git a/pkg/app/msg/message.go b/tools/app/msg/message.go similarity index 100% rename from pkg/app/msg/message.go rename to tools/app/msg/message.go diff --git a/pkg/app/return.go b/tools/app/return.go similarity index 100% rename from pkg/app/return.go rename to tools/app/return.go diff --git a/pkg/captcha/captcha.go b/tools/captcha/captcha.go similarity index 100% rename from pkg/captcha/captcha.go rename to tools/captcha/captcha.go diff --git a/config/application.go b/tools/config/application.go similarity index 69% rename from config/application.go rename to tools/config/application.go index 94c45cd4..9a1bd861 100644 --- a/config/application.go +++ b/tools/config/application.go @@ -3,30 +3,26 @@ package config import "github.com/spf13/viper" type Application struct { - IsInit bool ReadTimeout int WriterTimeout int Host string Port string Name string JwtSecret string - LogPath string - Env string - EnvMsg string + Mode string + DemoMsg string } func InitApplication(cfg *viper.Viper) *Application { return &Application{ - IsInit: cfg.GetBool("isInit"), ReadTimeout: cfg.GetInt("readTimeout"), WriterTimeout: cfg.GetInt("writerTimeout"), Host: cfg.GetString("host"), Port: cfg.GetString("port"), Name: cfg.GetString("name"), JwtSecret: cfg.GetString("jwtSecret"), - LogPath: cfg.GetString("logPath"), - Env: cfg.GetString("env"), - EnvMsg: cfg.GetString("envMsg"), + Mode: cfg.GetString("mode"), + DemoMsg: cfg.GetString("demoMsg"), } } diff --git a/config/config.go b/tools/config/config.go similarity index 50% rename from config/config.go rename to tools/config/config.go index e608053a..68facd1f 100644 --- a/config/config.go +++ b/tools/config/config.go @@ -1,20 +1,36 @@ package config import ( + "fmt" "github.com/spf13/viper" + "io/ioutil" "log" + "os" + "strings" ) var cfgDatabase *viper.Viper var cfgApplication *viper.Viper var cfgJwt *viper.Viper +var cfgLog *viper.Viper -func init() { - viper.SetConfigName("settings") - viper.AddConfigPath("./config") - err := viper.ReadInConfig() +//func init() { +// InitConfig("settings.dev") +//} + +//载入配置文件 +func ConfigSetup(path string) { + viper.SetConfigFile(path) + content, err := ioutil.ReadFile(path) if err != nil { - log.Println(err) + log.Fatal(fmt.Sprintf("Read config file fail: %s", err.Error())) + } + + + //Replace environment variables + err = viper.ReadConfig(strings.NewReader(os.ExpandEnv(string(content)))) + if err != nil { + log.Fatal(fmt.Sprintf("Parse config file fail: %s", err.Error())) } cfgDatabase = viper.Sub("settings.database") @@ -34,13 +50,19 @@ func init() { panic("config not found settings.jwt") } JwtConfig = InitJwt(cfgJwt) + + cfgLog = viper.Sub("settings.log") + if cfgLog == nil { + panic("config not found settings.log") + } + LogConfig = InitLog(cfgLog) } func SetApplicationIsInit() { - SetConfig("./config","settings.application.isInit", false) + SetConfig("./config", "settings.application.isInit", false) } -func SetConfig(configPath string,key string,value interface{}){ +func SetConfig(configPath string, key string, value interface{}) { viper.AddConfigPath(configPath) viper.Set(key, value) viper.WriteConfig() diff --git a/config/database.go b/tools/config/database.go similarity index 88% rename from config/database.go rename to tools/config/database.go index fe734e66..87f341d1 100644 --- a/config/database.go +++ b/tools/config/database.go @@ -6,7 +6,7 @@ type Database struct { Dbtype string Host string Port int - Database string + Name string Username string Password string } @@ -16,7 +16,7 @@ func InitDatabase(cfg *viper.Viper) *Database { Port: cfg.GetInt("port"), Dbtype: cfg.GetString("dbType"), Host: cfg.GetString("host"), - Database: cfg.GetString("database"), + Name: cfg.GetString("name"), Username: cfg.GetString("username"), Password: cfg.GetString("password"), } diff --git a/config/jwt.go b/tools/config/jwt.go similarity index 100% rename from config/jwt.go rename to tools/config/jwt.go diff --git a/tools/config/log.go b/tools/config/log.go new file mode 100644 index 00000000..bf94e67c --- /dev/null +++ b/tools/config/log.go @@ -0,0 +1,15 @@ +package config + +import "github.com/spf13/viper" + +type Log struct { + Dir string +} + +func InitLog(cfg *viper.Viper) *Log { + return &Log{ + Dir: cfg.GetString("dir"), + } +} + +var LogConfig = new(Log) diff --git a/tools/env.go b/tools/env.go new file mode 100644 index 00000000..9cb337b8 --- /dev/null +++ b/tools/env.go @@ -0,0 +1,13 @@ +package tools + +type ( + Mode string +) + +const ( + ModeDev Mode = "dev" //开发模式 + ModeTest Mode = "test" //测试模式 + ModeProd Mode = "prod" //生产模式 + Mysql = "mysql" //mysql数据库标识 + Sqlite = "sqlite" //sqlite +) diff --git a/pkg/utils/float64.go b/tools/float64.go similarity index 88% rename from pkg/utils/float64.go rename to tools/float64.go index 82a93024..bc3cf866 100644 --- a/pkg/utils/float64.go +++ b/tools/float64.go @@ -1,4 +1,4 @@ -package utils +package tools import "strconv" diff --git a/pkg/utils/int.go b/tools/int.go similarity index 84% rename from pkg/utils/int.go rename to tools/int.go index 5d0b7606..43f0643c 100644 --- a/pkg/utils/int.go +++ b/tools/int.go @@ -1,4 +1,4 @@ -package utils +package tools import "strconv" diff --git a/pkg/utils/int64.go b/tools/int64.go similarity index 86% rename from pkg/utils/int64.go rename to tools/int64.go index d48bfff0..e469ed33 100644 --- a/pkg/utils/int64.go +++ b/tools/int64.go @@ -1,4 +1,4 @@ -package utils +package tools import "strconv" diff --git a/pkg/utils/ip.go b/tools/ip.go similarity index 97% rename from pkg/utils/ip.go rename to tools/ip.go index 2fdee857..a07287c2 100644 --- a/pkg/utils/ip.go +++ b/tools/ip.go @@ -1,4 +1,4 @@ -package utils +package tools import ( "encoding/json" diff --git a/tools/logger.go b/tools/logger.go new file mode 100644 index 00000000..179bfb82 --- /dev/null +++ b/tools/logger.go @@ -0,0 +1,56 @@ +package tools + +import ( + "errors" + log "github.com/sirupsen/logrus" + "github.com/spf13/viper" + "os" + "time" +) + +func InitLogger() { + switch Mode(viper.GetString("settings.application.mode")) { + case ModeDev, ModeTest: + log.SetOutput(os.Stdout) + log.SetLevel(log.TraceLevel) + case ModeProd: + file, err := os.OpenFile(viper.GetString("logger.dir")+"/api-"+time.Now().Format("2006-01-02")+".log", os.O_WRONLY|os.O_APPEND|os.O_CREATE|os.O_SYNC, 0600) + if err != nil { + log.Fatalln("log init failed") + } + + var info os.FileInfo + info, err = file.Stat() + if err != nil { + log.Fatal(err) + } + fileWriter := logFileWriter{file, info.Size()} + log.SetOutput(&fileWriter) + log.SetLevel(log.ErrorLevel) + } + + log.SetReportCaller(true) +} + +type logFileWriter struct { + file *os.File + size int64 +} + +func (p *logFileWriter) Write(data []byte) (n int, err error) { + if p == nil { + return 0, errors.New("logFileWriter is nil") + } + if p.file == nil { + return 0, errors.New("file not opened") + } + n, e := p.file.Write(data) + p.size += int64(n) + //每天一个文件 + if p.file.Name() != viper.GetString("logger.dir")+"/api-"+time.Now().Format("2006-01-02")+".log" { + p.file.Close() + p.file, _ = os.OpenFile(viper.GetString("logger.dir")+"/api-"+time.Now().Format("2006-01-02")+".log", os.O_WRONLY|os.O_APPEND|os.O_CREATE|os.O_SYNC, 0600) + p.size = 0 + } + return n, e +} diff --git a/pkg/utils/string.go b/tools/string.go similarity index 98% rename from pkg/utils/string.go rename to tools/string.go index 9eca5e34..d266be0a 100644 --- a/pkg/utils/string.go +++ b/tools/string.go @@ -1,4 +1,4 @@ -package utils +package tools import ( "encoding/json" diff --git a/pkg/utils/url.go b/tools/url.go similarity index 96% rename from pkg/utils/url.go rename to tools/url.go index 3b61d94f..c5ac0278 100644 --- a/pkg/utils/url.go +++ b/tools/url.go @@ -1,4 +1,4 @@ -package utils +package tools import ( "github.com/gin-gonic/gin" diff --git a/pkg/utils/user.go b/tools/user.go similarity index 99% rename from pkg/utils/user.go rename to tools/user.go index 2cb24a91..84ecc013 100644 --- a/pkg/utils/user.go +++ b/tools/user.go @@ -1,4 +1,4 @@ -package utils +package tools import ( "fmt" diff --git a/pkg/utils.go b/tools/utils.go similarity index 94% rename from pkg/utils.go rename to tools/utils.go index 25ecf5d9..ac0a5148 100644 --- a/pkg/utils.go +++ b/tools/utils.go @@ -1,4 +1,4 @@ -package pkg +package tools import ( "golang.org/x/crypto/bcrypt" @@ -33,7 +33,7 @@ func Assert(condition bool, msg string, code ...int) { if len(code) > 0 { statusCode = code[0] } - panic("CustomErroe#" + strconv.Itoa(statusCode) + "#" + msg) + panic("CustomError#" + strconv.Itoa(statusCode) + "#" + msg) } }