Merge pull request #374 from go-admin-team/dev

优化生成的swagger
This commit is contained in:
lwnmengjing
2021-03-24 22:49:33 +08:00
committed by GitHub
37 changed files with 2418 additions and 2450 deletions
+4 -2
View File
@@ -1,14 +1,16 @@
package monitor
import (
"go-admin/common/apis"
"runtime"
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
"github.com/shirou/gopsutil/cpu"
"github.com/shirou/gopsutil/disk"
"github.com/shirou/gopsutil/mem"
"go-admin/common/apis"
)
const (
@@ -25,7 +27,7 @@ type Monitor struct {
// @Summary 系统信息
// @Description 获取JSON
// @Tags 系统信息
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/settings/serverInfo [get]
func (e *Monitor) ServerInfo(c *gin.Context) {
+6 -5
View File
@@ -5,6 +5,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
"github.com/google/uuid"
"go-admin/app/admin/models"
@@ -68,7 +69,7 @@ func (e *SysUser) GetSysUserList(c *gin.Context) {
// @Description 获取JSON
// @Tags 用户
// @Param userId path int true "用户编码"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/sysUser/{userId} [get]
// @Security Bearer
func (e *SysUser) GetSysUser(c *gin.Context) {
@@ -109,7 +110,7 @@ func (e *SysUser) GetSysUser(c *gin.Context) {
// @Tags 用户
// @Accept application/json
// @Product application/json
// @Param data body models.SysUser true "用户数据"
// @Param data body dto.SysUserControl true "用户数据"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/sysUser [post]
@@ -156,7 +157,7 @@ func (e *SysUser) InsertSysUser(c *gin.Context) {
// @Tags 用户
// @Accept application/json
// @Product application/json
// @Param data body models.SysUser true "body"
// @Param data body dto.SysUserControl true "body"
// @Success 200 {string} string "{"code": 200, "message": "修改成功"}"
// @Success 200 {string} string "{"code": -1, "message": "修改失败"}"
// @Router /api/v1/sysuser/{userId} [put]
@@ -303,7 +304,7 @@ func (e *SysUser) InsetSysUserAvatar(c *gin.Context) {
// @Accept application/json
// @Product application/json
// @Param data body dto.PassWord true "body"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/user/pwd [post]
// @Security Bearer
func (e *SysUser) SysUserUpdatePwd(c *gin.Context) {
@@ -343,7 +344,7 @@ func (e *SysUser) SysUserUpdatePwd(c *gin.Context) {
// @Summary 获取个人中心用户
// @Description 获取JSON
// @Tags 个人中心
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/user/profile [get]
// @Security Bearer
func (e *SysUser) GetSysUserProfile(c *gin.Context) {
+5 -4
View File
@@ -5,6 +5,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
"go-admin/app/admin/models/system"
"go-admin/app/admin/service"
@@ -25,7 +26,7 @@ type SysDictData struct {
// @Param dictType query string false "dictType"
// @Param pageSize query int false "页条数"
// @Param pageIndex query int false "页码"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/dict/data [get]
// @Security Bearer
func (e *SysDictData) GetSysDictDataList(c *gin.Context) {
@@ -65,7 +66,7 @@ func (e *SysDictData) GetSysDictDataList(c *gin.Context) {
// @Description 获取JSON
// @Tags 字典数据
// @Param dictCode path int true "字典编码"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/dict/data/{dictCode} [get]
// @Security Bearer
func (e *SysDictData) GetSysDictData(c *gin.Context) {
@@ -104,7 +105,7 @@ func (e *SysDictData) GetSysDictData(c *gin.Context) {
// @Tags 字典数据
// @Accept application/json
// @Product application/json
// @Param data body system.DictType true "data"
// @Param data body dto.SysDictDataControl true "data"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/dict/data [post]
@@ -147,7 +148,7 @@ func (e *SysDictData) InsertSysDictData(c *gin.Context) {
// @Tags 字典数据
// @Accept application/json
// @Product application/json
// @Param data body models.DictType true "body"
// @Param data body dto.SysDictDataControl true "body"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/dict/data/{dictCode} [put]
+6 -5
View File
@@ -5,6 +5,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
"go-admin/app/admin/models/system"
"go-admin/app/admin/service"
@@ -25,7 +26,7 @@ type SysDictType struct {
// @Param dictType query string false "dictType"
// @Param pageSize query int false "页条数"
// @Param pageIndex query int false "页码"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/dict/type [get]
// @Security Bearer
func (e *SysDictType) GetSysDictTypeList(c *gin.Context) {
@@ -63,7 +64,7 @@ func (e *SysDictType) GetSysDictTypeList(c *gin.Context) {
// @Description 获取JSON
// @Tags 字典类型
// @Param dictId path int true "字典类型编码"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/dict/type/{dictId} [get]
// @Security Bearer
func (e *SysDictType) GetSysDictType(c *gin.Context) {
@@ -100,7 +101,7 @@ func (e *SysDictType) GetSysDictType(c *gin.Context) {
// @Tags 字典类型
// @Accept application/json
// @Product application/json
// @Param data body models.DictType true "data"
// @Param data body dto.SysDictTypeControl true "data"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/dict/type [post]
@@ -142,7 +143,7 @@ func (e *SysDictType) InsertSysDictType(c *gin.Context) {
// @Tags 字典类型
// @Accept application/json
// @Product application/json
// @Param data body models.DictType true "body"
// @Param data body dto.SysDictTypeControl true "body"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/dict/type/{dictId} [put]
@@ -226,7 +227,7 @@ func (e *SysDictType) DeleteSysDictType(c *gin.Context) {
// @Param dictName query string false "dictName"
// @Param dictId query string false "dictId"
// @Param dictType query string false "dictType"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/dict/type-option-select [get]
// @Security Bearer
func (e *SysDictType) GetSysDictTypeAll(c *gin.Context) {
+1 -1
View File
@@ -36,4 +36,4 @@ $(function(){
func HelloWorld(c *gin.Context) {
c.Header("Content-Type", "text/html; charset=utf-8")
c.String(200, INDEX)
}
}
+4 -4
View File
@@ -16,7 +16,7 @@ import (
// var Rm models.RoleMenu
// err := c.ShouldBind(&Rm)
// result, err := Rm.Get()
// var res app.Response
// var res response.Response
// if err != nil {
// res.Msg = "抱歉未找到相关信息"
// c.JSON(http.StatusOK, res.ReturnError(200))
@@ -33,7 +33,7 @@ type RoleMenuPost struct {
//func InsertRoleMenu(c *gin.Context) {
//
// var res app.Response
// var res response.Response
// res.Msg = "添加成功"
// c.JSON(http.StatusOK, res.ReturnOK())
// return
@@ -55,12 +55,12 @@ type RoleMenuPost struct {
// fmt.Println(menuId)
// _, err := t.Delete(id, menuId)
// if err != nil {
// var res app.Response
// var res response.Response
// res.Msg = "删除失败"
// c.JSON(http.StatusOK, res.ReturnError(200))
// return
// }
// var res app.Response
// var res response.Response
// res.Msg = "删除成功"
// c.JSON(http.StatusOK, res.ReturnOK())
// return
+1 -1
View File
@@ -53,7 +53,7 @@ func (e *SysSetting) GetSetting(c *gin.Context) {
// @Summary 更新或提交系统信息
// @Description 获取JSON
// @Tags 系统信息
// @Param data body models.SysUser true "body"
// @Param data body dto.SysSettingControl true "body"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/system/setting [post]
@@ -62,11 +62,10 @@ func (e *SysConfig) GetSysConfigBySysApp(c *gin.Context) {
e.Error(c, 500, err, "参数验证失败")
return
}
// 控制只读前台的数据
d.IsFrontend = 1
list := make([]system.SysConfig, 0)
s := service.SysConfig{}
s.Log = log
@@ -268,4 +267,4 @@ func (e *SysConfig) GetSysConfigByKEYForService(c *gin.Context) {
return
}
e.OK(c, v, s.Msg)
}
}
+6 -5
View File
@@ -5,6 +5,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
"go-admin/app/admin/models/system"
"go-admin/app/admin/service"
@@ -22,7 +23,7 @@ type SysDept struct {
// @Param name query string false "name"
// @Param id query string false "id"
// @Param position query string false "position"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/dept [get]
// @Security Bearer
func (e *SysDept) GetSysDeptList(c *gin.Context) {
@@ -59,7 +60,7 @@ func (e *SysDept) GetSysDeptList(c *gin.Context) {
// @Tags 部门
// @Param deptId path string false "deptId"
// @Param position query string false "position"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/dept/{deptId} [get]
// @Security Bearer
func (e *SysDept) GetSysDept(c *gin.Context) {
@@ -96,7 +97,7 @@ func (e *SysDept) GetSysDept(c *gin.Context) {
// @Tags 部门
// @Accept application/json
// @Product application/json
// @Param data body models.SysDept true "data"
// @Param data body dto.SysDeptControl true "data"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/dept [post]
@@ -143,7 +144,7 @@ func (e *SysDept) InsertSysDept(c *gin.Context) {
// @Accept application/json
// @Product application/json
// @Param id path int true "id"
// @Param data body models.SysDept true "body"
// @Param data body dto.SysDeptControl true "body"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/dept/{deptId} [put]
@@ -184,7 +185,7 @@ func (e *SysDept) UpdateSysDept(c *gin.Context) {
// @Summary 删除部门
// @Description 删除数据
// @Tags 部门
// @Param data body []int true "body"
// @Param data body dto.SysDeptById true "body"
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
// @Router /api/v1/dept [delete]
+2 -2
View File
@@ -152,7 +152,7 @@ func (e *SysMenu) InsertSysMenu(c *gin.Context) {
// @Accept application/x-www-form-urlencoded
// @Product application/x-www-form-urlencoded
// @Param id path int true "id"
// @Param data body models.Menu true "body"
// @Param data body dto.SysMenuControl true "body"
// @Success 200 {string} string "{"code": 200, "message": "修改成功"}"
// @Success 200 {string} string "{"code": -1, "message": "修改失败"}"
// @Router /api/v1/menu/{id} [put]
@@ -195,7 +195,7 @@ func (e *SysMenu) UpdateSysMenu(c *gin.Context) {
// @Summary 删除菜单
// @Description 删除数据
// @Tags 菜单
// @Param data body []int true "body"
// @Param data body dto.SysMenuById true "body"
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
// @Router /api/v1/menu/ [delete]
+5 -4
View File
@@ -5,6 +5,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
"go-admin/app/admin/models/system"
"go-admin/app/admin/service"
@@ -23,7 +24,7 @@ type SysPost struct {
// @Param postCode query string false "postCode"
// @Param postId query string false "postId"
// @Param status query string false "status"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/post [get]
// @Security Bearer
func (e *SysPost) GetSysPostList(c *gin.Context) {
@@ -60,7 +61,7 @@ func (e *SysPost) GetSysPostList(c *gin.Context) {
// @Description 获取JSON
// @Tags 岗位
// @Param postId path int true "postId"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/post/{postId} [get]
// @Security Bearer
func (e *SysPost) GetSysPost(c *gin.Context) {
@@ -97,7 +98,7 @@ func (e *SysPost) GetSysPost(c *gin.Context) {
// @Tags 岗位
// @Accept application/json
// @Product application/json
// @Param data body models.Post true "data"
// @Param data body dto.SysPostControl true "data"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/post [post]
@@ -143,7 +144,7 @@ func (e *SysPost) InsertSysPost(c *gin.Context) {
// @Tags 岗位
// @Accept application/json
// @Product application/json
// @Param data body models.Post true "body"
// @Param data body dto.SysPostControl true "body"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/post/ [put]
+4 -3
View File
@@ -5,6 +5,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
"go-admin/app/admin/models/system"
"go-admin/app/admin/service"
@@ -25,7 +26,7 @@ type SysRole struct {
// @Param roleKey query string false "roleKey"
// @Param pageSize query int false "页条数"
// @Param pageIndex query int false "页码"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/role [get]
// @Security Bearer
func (e *SysRole) GetSysRoleList(c *gin.Context) {
@@ -100,7 +101,7 @@ func (e *SysRole) GetSysRole(c *gin.Context) {
// @Tags 角色/Role
// @Accept application/json
// @Product application/json
// @Param data body models.SysRole true "data"
// @Param data body dto.SysRoleControl true "data"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/role [post]
@@ -153,7 +154,7 @@ func (e *SysRole) InsertSysRole(c *gin.Context) {
// @Tags 角色/Role
// @Accept application/json
// @Product application/json
// @Param data body models.SysRole true "body"
// @Param data body dto.SysRoleControl true "body"
// @Success 200 {string} string "{"code": 200, "message": "修改成功"}"
// @Success 200 {string} string "{"code": -1, "message": "修改失败"}"
// @Router /api/v1/role/{id} [put]
+2 -1
View File
@@ -5,6 +5,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
"go-admin/app/admin/models/tools"
)
@@ -15,7 +16,7 @@ import (
// @Param tableName query string false "tableName / 数据表名称"
// @Param pageSize query int false "pageSize / 页条数"
// @Param pageIndex query int false "pageIndex / 页码"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/db/columns/page [get]
func (e *Gen) GetDBColumnList(c *gin.Context) {
log := e.GetLogger(c)
+3 -2
View File
@@ -7,6 +7,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/config"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
"go-admin/app/admin/models/tools"
)
@@ -17,10 +18,10 @@ import (
// @Param tableName query string false "tableName / 数据表名称"
// @Param pageSize query int false "pageSize / 页条数"
// @Param pageIndex query int false "pageIndex / 页码"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/db/tables/page [get]
func (e *Gen) GetDBTableList(c *gin.Context) {
//var res app.Response
//var res response.Response
var data tools.DBTables
var err error
var pageSize = 10
+48
View File
@@ -3,7 +3,9 @@ package tools
import (
"bytes"
"net/http"
"strconv"
"text/template"
"time"
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/api"
@@ -135,6 +137,30 @@ func (e *Gen) GenCodeV3(c *gin.Context) {
e.OK(c, "", "Code generated successfully")
}
func (e *Gen) GenApiToFile(c *gin.Context) {
log := e.GetLogger(c)
table := tools.SysTables{}
id, err := pkg.StringToInt(c.Param("tableId"))
if err != nil {
log.Error(err)
e.Error(c, 500, err, "")
return
}
db, err := pkg.GetOrm(c)
if err != nil {
log.Errorf("get db connection error, %s", err.Error())
e.Error(c, http.StatusInternalServerError, err, "数据库连接获取失败")
return
}
table.TableId = id
tab, _ := table.Get(db)
e.genApiToFile(c, tab)
e.OK(c, "", "Code generated successfully")
}
func (e *Gen) NOActionsGenV3(c *gin.Context, tab tools.SysTables) {
log := e.GetLogger(c)
@@ -219,6 +245,28 @@ func (e *Gen) NOActionsGenV3(c *gin.Context, tab tools.SysTables) {
}
func (e *Gen) genApiToFile(c *gin.Context, tab tools.SysTables) {
log := e.GetLogger(c)
basePath := "template/"
t1, err := template.ParseFiles(basePath + "api_migrate.template")
if err != nil {
log.Error(err)
e.Error(c, 500, err, "")
return
}
i := strconv.FormatInt(time.Now().UnixNano()/1e6, 10)
var b1 bytes.Buffer
err = t1.Execute(&b1, struct {
tools.SysTables
GenerateTime string
}{tab, i})
pkg.FileCreate(b1, "./cmd/migrate/migration/version/"+i+"_migrate.go")
}
func (e *Gen) ActionsGenV3(c *gin.Context, tab tools.SysTables) {
log := api.GetRequestLogger(c)
basePath := "template/v4/"
+3 -2
View File
@@ -7,6 +7,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
"gorm.io/gorm"
"go-admin/app/admin/models/tools"
@@ -23,7 +24,7 @@ type SysTable struct {
// @Param tableName query string false "tableName / 数据表名称"
// @Param pageSize query int false "pageSize / 页条数"
// @Param pageIndex query int false "pageIndex / 页码"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/sys/tables/page [get]
func (e *SysTable) GetSysTableList(c *gin.Context) {
log := e.GetLogger(c)
@@ -62,7 +63,7 @@ func (e *SysTable) GetSysTableList(c *gin.Context) {
// @Description 获取JSON
// @Tags 工具 - 生成表
// @Param configKey path int true "configKey"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
// @Router /api/v1/sys/tables/info/{tableId} [get]
// @Security Bearer
func (e *SysTable) GetSysTables(c *gin.Context) {
+1 -1
View File
@@ -56,7 +56,7 @@ func IdentityHandler(c *gin.Context) interface{} {
// @Description 注意:开发模式:需要注意全部字段不能为空,账号密码外可以传入0值
// @Accept application/json
// @Product application/json
// @Param account body models.Login true "account"
// @Param account body system.Login true "account"
// @Success 200 {string} string "{"code": 200, "expire": "2019-08-07T12:45:48+08:00", "token": ".eyJleHAiOjE1NjUxNTMxNDgsImlkIjoiYWRtaW4iLCJvcmlnX2lhdCI6MTU2NTE0OTU0OH0.-zvzHvbg0A" }"
// @Router /login [post]
func Authenticator(c *gin.Context) (interface{}, error) {
+1 -1
View File
@@ -27,4 +27,4 @@ func (e *SysConfig) Generate() models.ActiveRecord {
func (e *SysConfig) GetId() interface{} {
return e.Id
}
}
+3 -1
View File
@@ -2,6 +2,7 @@ package router
import (
"github.com/go-admin-team/go-admin-core/sdk"
"github.com/go-admin-team/go-admin-core/sdk/api"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"os"
@@ -35,7 +36,8 @@ func InitRouter() {
}
r.Use(common.Sentinel()).
Use(common.RequestId(pkg.TrafficKey))
Use(common.RequestId(pkg.TrafficKey)).
Use(api.SetRequestLogger)
middleware.InitMiddleware(r)
// the jwt middleware
authMiddleware, err := middleware.AuthInit()
+1 -2
View File
@@ -34,5 +34,4 @@ func registerSysConfigRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMidd
r2.GET("", api.GetSysConfigBySysApp)
}
}
}
+2
View File
@@ -65,6 +65,8 @@ func sysNoCheckRoleRouter(r *gin.RouterGroup) {
gen := &tools.Gen{}
v1.GET("/gen/preview/:tableId", gen.Preview)
v1.GET("/gen/toproject/:tableId", gen.GenCodeV3)
v1.GET("/gen/apitofile/:tableId", gen.GenApiToFile)
v1.GET("/gen/todb/:tableId", gen.GenMenuAndApi)
sysTable := &tools.SysTable{}
v1.GET("/gen/tabletree", sysTable.GetSysTablesTree)
+1 -1
View File
@@ -116,4 +116,4 @@ func (s *SysConfigById) Bind(ctx *gin.Context) error {
func (s *SysConfigById) GenerateM() (*system.SysConfig, error) {
return &system.SysConfig{}, nil
}
}
+1 -1
View File
@@ -131,4 +131,4 @@ func (e *SysConfig) GetSysConfigByKEY(c *dto.SysConfigControl) error {
}
return nil
}
}
@@ -25,4 +25,4 @@ func _1615948084336Test(db *gorm.DB, version string) error {
Version: version,
}).Error
})
}
}
@@ -30,4 +30,4 @@ func _1615950701614Test(db *gorm.DB, version string) error {
Version: version,
}).Error
})
}
}
@@ -30,4 +30,4 @@ func _1615961953379Test(db *gorm.DB, version string) error {
Version: version,
}).Error
})
}
}
+2 -2
View File
@@ -2,11 +2,11 @@ package global
const (
// go-admin Version Info
Version = "1.3.0"
Version = "1.3.1rc.1"
)
var (
Source string
Driver string
DBName string
)
)
+731 -888
View File
File diff suppressed because it is too large Load Diff
+731 -888
View File
File diff suppressed because it is too large Load Diff
+479 -589
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -8,7 +8,7 @@ require (
github.com/aliyun/aliyun-oss-go-sdk v0.0.0-20190307165228-86c17b95fcd5
github.com/casbin/casbin/v2 v2.25.1
github.com/gin-gonic/gin v1.6.3
github.com/go-admin-team/go-admin-core v1.3.0-rc.0.0.20210317043714-3dd2b8cbf8cc
github.com/go-admin-team/go-admin-core v1.3.1-0.20210324084642-7c164d76fc11
github.com/google/uuid v1.2.0
github.com/mojocn/base64Captcha v1.3.1
github.com/mssola/user_agent v0.5.2
+12
View File
@@ -4,6 +4,18 @@ import (
"go-admin/cmd"
)
//go:generate swag init --parseDependency
// @title go-admin API
// @version 1.3.1
// @description 基于Gin + Vue + Element UI的前后端分离权限管理系统的接口文档
// @description 添加qq群: 74520518 进入技术交流群 请备注,谢谢!
// @license.name MIT
// @license.url https://github.com/go-admin-team/go-admin/blob/master/LICENSE.md
// @securityDefinitions.apikey Bearer
// @in header
// @name Authorization
func main() {
cmd.Execute()
}
+326
View File
@@ -0,0 +1,326 @@
package version
import (
"gorm.io/gorm"
"runtime"
"time"
"github.com/go-admin-team/go-admin-core/sdk/pkg"
"go-admin/cmd/migrate/migration"
common "go-admin/common/models"
)
type Menu struct {
MenuId int `json:"menuId" gorm:"primaryKey;autoIncrement"`
MenuName string `json:"menuName" gorm:"size:128;"`
Title string `json:"title" gorm:"size:128;"`
Icon string `json:"icon" gorm:"size:128;"`
Path string `json:"path" gorm:"size:128;"`
Paths string `json:"paths" gorm:"size:128;"`
MenuType string `json:"menuType" gorm:"size:1;"`
Action string `json:"action" gorm:"size:16;"`
Permission string `json:"permission" gorm:"size:255;"`
ParentId int `json:"parentId" gorm:"size:11;"`
NoCache bool `json:"noCache" gorm:"size:8;"`
Breadcrumb string `json:"breadcrumb" gorm:"size:255;"`
Component string `json:"component" gorm:"size:255;"`
Sort int `json:"sort" gorm:"size:4;"`
Visible string `json:"visible" gorm:"size:1;"`
CreateBy string `json:"createBy" gorm:"size:128;"`
UpdateBy string `json:"updateBy" gorm:"size:128;"`
IsFrame string `json:"isFrame" gorm:"size:1;DEFAULT:0;"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt *time.Time `json:"deletedAt"`
}
func (Menu) TableName() string {
return "sys_menu"
}
func init() {
_, fileName, _, _ := runtime.Caller(0)
migration.Migrate.SetVersion(migration.GetFilename(fileName), _{{.GenerateTime}}Test)
}
func _{{.GenerateTime}}Test(db *gorm.DB, version string) error {
return db.Transaction(func(tx *gorm.DB) error {
timeNow := pkg.GetCurrentTime()
Mmenu := Menu{}
Mmenu.MenuName = "{{.TBName}}Manage"
Mmenu.Title = "{{.TableComment}}"
Mmenu.Icon = "pass"
Mmenu.Path = "/{{.TBName}}"
Mmenu.MenuType = "M"
Mmenu.Action = "无"
Mmenu.ParentId = 0
Mmenu.NoCache = false
Mmenu.Component = "Layout"
Mmenu.Sort = 0
Mmenu.Visible = "0"
Mmenu.IsFrame = "0"
Mmenu.CreateBy = "1"
Mmenu.UpdateBy = "1"
Mmenu.CreatedAt = timeNow
Mmenu.UpdatedAt = timeNow
// Mmenu.MenuId, err = Mmenu.Create(db)
err := tx.Create(&Mmenu).Error
if err != nil {
return err
}
Cmenu := Menu{}
Cmenu.MenuName = "{{.TBName}}"
Cmenu.Title = "{{.TableComment}}"
Cmenu.Icon = "pass"
Cmenu.Path = "{{.TBName}}"
Cmenu.MenuType = "C"
Cmenu.Action = "无"
Cmenu.Permission = "{{.PackageName}}:{{.BusinessName}}:list"
Cmenu.ParentId = Mmenu.MenuId
Cmenu.NoCache = false
Cmenu.Component = "/{{.BusinessName}}/index"
Cmenu.Sort = 0
Cmenu.Visible = "0"
Cmenu.IsFrame = "0"
Cmenu.CreateBy = "1"
Cmenu.UpdateBy = "1"
Cmenu.CreatedAt = timeNow
Cmenu.UpdatedAt = timeNow
// Cmenu.MenuId, err = Cmenu.Create(db)
err = tx.Create(&Cmenu).Error
if err != nil {
return err
}
MList := Menu{}
MList.MenuName = ""
MList.Title = "分页获取{{.TableComment}}"
MList.Icon = ""
MList.Path = "{{.TBName}}"
MList.MenuType = "F"
MList.Action = "无"
MList.Permission = "{{.PackageName}}:{{.BusinessName}}:query"
MList.ParentId = Cmenu.MenuId
MList.NoCache = false
MList.Sort = 0
MList.Visible = "0"
MList.IsFrame = "0"
MList.CreateBy = "1"
MList.UpdateBy = "1"
MList.CreatedAt = timeNow
MList.UpdatedAt = timeNow
// MList.MenuId, err = MList.Create(db)
err = tx.Create(&MList).Error
if err != nil {
return err
}
MCreate := Menu{}
MCreate.MenuName = ""
MCreate.Title = "创建{{.TableComment}}"
MCreate.Icon = ""
MCreate.Path = "{{.TBName}}"
MCreate.MenuType = "F"
MCreate.Action = "无"
MCreate.Permission = "{{.PackageName}}:{{.BusinessName}}:add"
MCreate.ParentId = Cmenu.MenuId
MCreate.NoCache = false
MCreate.Sort = 0
MCreate.Visible = "0"
MCreate.IsFrame = "0"
MCreate.CreateBy = "1"
MCreate.UpdateBy = "1"
MCreate.CreatedAt = timeNow
MCreate.UpdatedAt = timeNow
// MCreate.MenuId, err = MCreate.Create(db)
err = tx.Create(&MCreate).Error
if err != nil {
return err
}
MUpdate := Menu{}
MUpdate.MenuName = ""
MUpdate.Title = "修改{{.TableComment}}"
MUpdate.Icon = ""
MUpdate.Path = "{{.TBName}}"
MUpdate.MenuType = "F"
MUpdate.Action = "无"
MUpdate.Permission ="{{.PackageName}}:{{.BusinessName}}:edit"
MUpdate.ParentId = Cmenu.MenuId
MUpdate.NoCache = false
MUpdate.Sort = 0
MUpdate.Visible = "0"
MUpdate.IsFrame = "0"
MUpdate.CreateBy = "1"
MUpdate.UpdateBy = "1"
MUpdate.CreatedAt = timeNow
MUpdate.UpdatedAt = timeNow
// MUpdate.MenuId, err = MUpdate.Create(db)
err = tx.Create(&MUpdate).Error
if err != nil {
return err
}
MDelete := Menu{}
MDelete.MenuName = ""
MDelete.Title = "删除{{.TableComment}}"
MDelete.Icon = ""
MDelete.Path = "{{.TBName}}"
MDelete.MenuType = "F"
MDelete.Action = "无"
MDelete.Permission = "{{.PackageName}}:{{.BusinessName}}:remove"
MDelete.ParentId = Cmenu.MenuId
MDelete.NoCache = false
MDelete.Sort = 0
MDelete.Visible = "0"
MDelete.IsFrame = "0"
MDelete.CreateBy = "1"
MDelete.UpdateBy = "1"
MDelete.CreatedAt = timeNow
MDelete.UpdatedAt = timeNow
// MDelete.MenuId, err = MDelete.Create(db)
err = tx.Create(&MDelete).Error
if err != nil {
return err
}
var InterfaceId = 63
Amenu := Menu{}
Amenu.MenuName = "{{.TBName}}"
Amenu.Title = "{{.TableComment}}"
Amenu.Icon = "bug"
Amenu.Path = "{{.TBName}}"
Amenu.MenuType = "M"
Amenu.Action = "无"
Amenu.ParentId = InterfaceId
Amenu.NoCache = false
Amenu.Sort = 0
Amenu.Visible = "1"
Amenu.IsFrame = "0"
Amenu.CreateBy = "1"
Amenu.UpdateBy = "1"
Amenu.CreatedAt = timeNow
Amenu.UpdatedAt = timeNow
// Amenu.MenuId, err = Amenu.Create(db)
err = tx.Create(&Amenu).Error
if err != nil {
return err
}
AList := Menu{}
AList.MenuName = ""
AList.Title = "分页获取{{.TableComment}}"
AList.Icon = "bug"
AList.Path = "/api/v1/{{.ModuleName}}"
AList.MenuType = "A"
AList.Action = "GET"
AList.ParentId = Amenu.MenuId
AList.NoCache = false
AList.Sort = 0
AList.Visible = "1"
AList.IsFrame = "0"
AList.CreateBy = "1"
AList.UpdateBy = "1"
AList.CreatedAt = timeNow
AList.UpdatedAt = timeNow
// AList.MenuId, err = AList.Create(db)
err = tx.Create(&AList).Error
if err != nil {
return err
}
AGet := Menu{}
AGet.MenuName = ""
AGet.Title = "根据id获取{{.TableComment}}"
AGet.Icon = "bug"
AGet.Path = "/api/v1/{{.ModuleName}}/:id"
AGet.MenuType = "A"
AGet.Action = "GET"
AGet.ParentId = Amenu.MenuId
AGet.NoCache = false
AGet.Sort = 0
AGet.Visible = "1"
AGet.IsFrame = "0"
AGet.CreateBy = "1"
AGet.UpdateBy = "1"
AGet.CreatedAt = timeNow
AGet.UpdatedAt = timeNow
// AGet.MenuId, err = AGet.Create(db)
err = tx.Create(&AGet).Error
if err != nil {
return err
}
ACreate := Menu{}
ACreate.MenuName = ""
ACreate.Title = "创建{{.TableComment}}"
ACreate.Icon = "bug"
ACreate.Path = "/api/v1/{{.ModuleName}}"
ACreate.MenuType = "A"
ACreate.Action = "POST"
ACreate.ParentId = Amenu.MenuId
ACreate.NoCache = false
ACreate.Sort = 0
ACreate.Visible = "1"
ACreate.IsFrame = "0"
ACreate.CreateBy = "1"
ACreate.UpdateBy = "1"
ACreate.CreatedAt = timeNow
ACreate.UpdatedAt = timeNow
// ACreate.MenuId, err = ACreate.Create(db)
err = tx.Create(&ACreate).Error
if err != nil {
return err
}
AUpdate := Menu{}
AUpdate.MenuName = ""
AUpdate.Title = "修改{{.TableComment}}"
AUpdate.Icon = "bug"
AUpdate.Path = "/api/v1/{{.ModuleName}}/:id"
AUpdate.MenuType = "A"
AUpdate.Action = "PUT"
AUpdate.ParentId = Amenu.MenuId
AUpdate.NoCache = false
AUpdate.Sort = 0
AUpdate.Visible = "1"
AUpdate.IsFrame = "0"
AUpdate.CreateBy = "1"
AUpdate.UpdateBy = "1"
AUpdate.CreatedAt = timeNow
AUpdate.UpdatedAt = timeNow
// AUpdate.MenuId, err = AUpdate.Create(db)
err = tx.Create(&AUpdate).Error
if err != nil {
return err
}
ADelete := Menu{}
ADelete.MenuName = ""
ADelete.Title = "删除{{.TableComment}}"
ADelete.Icon = "bug"
ADelete.Path = "/api/v1/{{.ModuleName}}"
ADelete.MenuType = "A"
ADelete.Action = "DELETE"
ADelete.ParentId = Amenu.MenuId
ADelete.NoCache = false
ADelete.Sort = 0
ADelete.Visible = "1"
ADelete.IsFrame = "0"
ADelete.CreateBy = "1"
ADelete.UpdateBy = "1"
ADelete.CreatedAt = timeNow
ADelete.UpdatedAt = timeNow
//ADelete.MenuId, err = ADelete.Create(db)
err = tx.Create(&ADelete).Error
if err != nil {
return err
}
return tx.Create(&common.Migration{
Version: version,
}).Error
})
}
+15 -22
View File
@@ -5,10 +5,11 @@ import (
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
"go-admin/app/admin/models"
"go-admin/app/admin/service"
"go-admin/app/admin/service/dto"
"go-admin/app/{{.PackageName}}/models"
"go-admin/app/{{.PackageName}}/service"
"go-admin/app/{{.PackageName}}/service/dto"
"go-admin/common/actions"
"go-admin/common/apis"
)
@@ -23,13 +24,10 @@ type {{.ClassName}} struct {
{{ $tablename := .TBName -}}
{{ range .Columns -}}
{{$z := .IsQuery}}
{{- if ($z) -}}
// @Param {{.JsonField}} query {{.GoType}} false "{{.ColumnComment}}"
{{ end -}}
{{- end }}
{{- if ($z) -}}// @Param {{.JsonField}} query {{.GoType}} false "{{.ColumnComment}}"{{ end -}}{{- end }}
// @Param pageSize query int false "页条数"
// @Param pageIndex query int false "页码"
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
// @Success 200 {object} response.Response{data=response.Page{list=[]models.{{.ClassName}}}} "{"code": 200, "data": [...]}"
// @Router /api/v1/{{.ModuleName}} [get]
// @Security Bearer
// Get{{.ClassName}}List 获取{{.TableComment}}列表
@@ -72,9 +70,8 @@ func (e *{{.ClassName}}) Get{{.ClassName}}List(c *gin.Context) {
// @Description 获取{{.TableComment}}
// @Tags {{.TableComment}}
// @Param id path string false "id"
// @Success 200 {string} string "{"code": 200, "data": [...]}"
// @Success 200 {string} string "{"code": -1, "message": "抱歉未找到相关信息"}"
// @Router /api/v1/{{.ModuleName}} [get]
// @Success 200 {object} response.Response{data=models.{{.ClassName}}} "{"code": 200, "data": [...]}"
// @Router /api/v1/{{.ModuleName}}/{id} [get]
// @Security Bearer
// Get{{.ClassName}} 获取{{.TableComment}}
func (e *{{.ClassName}}) Get{{.ClassName}}(c *gin.Context) {
@@ -118,9 +115,8 @@ func (e *{{.ClassName}}) Get{{.ClassName}}(c *gin.Context) {
// @Accept application/json
// @Product application/json
// @Param data body dto.{{.ClassName}}Control true "data"
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
// @Router /api/v1/{{.ClassName}} [post]
// @Success 200 {object} response.Response "{"code": 200, "message": "添加成功"}"
// @Router /api/v1/{{.ModuleName}} [post]
// Insert{{.ClassName}} 创建{{.TableComment}}
func (e *{{.ClassName}}) Insert{{.ClassName}}(c *gin.Context) {
log := e.GetLogger(c)
@@ -167,9 +163,8 @@ func (e *{{.ClassName}}) Insert{{.ClassName}}(c *gin.Context) {
// @Accept application/json
// @Product application/json
// @Param data body dto.{{.ClassName}}Control true "body"
// @Success 200 {string} string "{"code": 200, "message": "修改成功"}"
// @Success 200 {string} string "{"code": -1, "message": "修改失败"}"
// @Router /api/v1/{{.ClassName}} [put]
// @Success 200 {object} response.Response "{"code": 200, "message": "修改成功"}"
// @Router /api/v1/{{.ModuleName}} [put]
// Update{{.ClassName}} 修改{{.TableComment}}
func (e *{{.ClassName}}) Update{{.ClassName}}(c *gin.Context) {
log := e.GetLogger(c)
@@ -214,11 +209,9 @@ func (e *{{.ClassName}}) Update{{.ClassName}}(c *gin.Context) {
// @Summary 删除{{.TableComment}}
// @Description 删除{{.TableComment}}
// @Tags {{.TableComment}}
// @Param id path int false "id"
// @Param ids body string false "ids"
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
// @Router /api/v1/{{.ClassName}}/{id} [delete]
// @Param ids body []int false "ids"
// @Success 200 {object} response.Response "{"code": 200, "message": "删除成功"}"
// @Router /api/v1/{{.ModuleName}} [delete]
// Delete{{.ClassName}} 删除{{.TableComment}}
func (e *{{.ClassName}}) Delete{{.ClassName}}(c *gin.Context) {
log := e.GetLogger(c)
@@ -4,7 +4,7 @@ import (
"github.com/gin-gonic/gin"
jwt "github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth"
"go-admin/app/admin/apis/{{.ModuleName}}"
"go-admin/app/{{.PackageName}}/apis/{{.ModuleName}}"
"go-admin/common/middleware"
)
@@ -23,4 +23,4 @@ func register{{.ClassName}}Router(v1 *gin.RouterGroup, authMiddleware *jwt.GinJW
r.PUT("/:id", api.Update{{.ClassName}})
r.DELETE("", api.Delete{{.ClassName}})
}
}
}
@@ -4,7 +4,7 @@ import (
"github.com/gin-gonic/gin"
jwt "github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth"
"go-admin/app/admin/apis/{{.ModuleName}}"
"go-admin/app/{{.PackageName}}/apis/{{.ModuleName}}"
)
func init() {
@@ -22,4 +22,4 @@ func register{{.ClassName}}Router(v1 *gin.RouterGroup, authMiddleware *jwt.GinJW
r.PUT("/:id", api.Update{{.ClassName}})
r.DELETE("", api.Delete{{.ClassName}})
}
}
}
+2 -2
View File
@@ -5,10 +5,10 @@ import (
"gorm.io/gorm"
"go-admin/app/admin/models"
"go-admin/app/{{.PackageName}}/models"
"go-admin/common/actions"
cDto "go-admin/common/dto"
"go-admin/app/admin/service/dto"
"go-admin/app/{{.PackageName}}/service/dto"
"go-admin/common/service"
)