From 8c554d7ee75c8e4f62d7f666a36c32bce6ddf004 Mon Sep 17 00:00:00 2001 From: zhangwenjian Date: Thu, 23 Jul 2020 12:03:17 +0800 Subject: [PATCH] =?UTF-8?q?clear=EF=BC=9Aformatting=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + apis/monitor/server.go | 1 - apis/system/config.go | 8 +- apis/system/dept.go | 16 +-- apis/system/dict/dictdata.go | 2 +- apis/system/index.go | 7 +- apis/system/post.go | 8 +- apis/tools/dbcolumns.go | 2 +- apis/tools/gen.go | 14 +-- cmd/api/server.go | 70 ++++++------ database/initialize.go | 1 - database/sqlite3-driver.go | 2 +- global/adm.go | 4 +- global/logger.go | 6 +- handler/ping.go | 2 +- handler/sd/check.go | 25 +++-- models/dictdata.go | 24 ++--- models/dicttype.go | 6 +- models/loginlog.go | 20 ++-- models/model.go | 4 +- models/operlog.go | 42 ++++---- models/post.go | 10 +- models/role.go | 18 ++-- models/sysuser.go | 7 +- models/tools/syscolumns.go | 4 +- models/tools/systables.go | 2 +- pkg/casbin/mycasbin.go | 2 - pkg/logger/logger.go | 6 +- router/router.go | 7 +- template/model.go.template | 136 +++++++++++------------ template/router.go.template | 8 +- template/vue.go.template | 202 +++++++++++++++++++---------------- test/api.go.template | 124 ++++++++++----------- test/gen_test.go | 1 - test/model.go.template | 120 ++++++++++----------- tools/app/model.go | 13 +-- tools/app/return.go | 4 +- tools/captcha/captcha.go | 8 +- tools/config/application.go | 2 +- tools/config/config.go | 3 - tools/config/database.go | 1 - tools/config/gen.go | 8 +- tools/config/log.go | 4 +- tools/env.go | 8 +- tools/file.go | 11 +- tools/float64.go | 2 +- tools/int.go | 2 +- tools/int64.go | 2 +- tools/ip.go | 2 +- tools/logger.go | 1 - tools/string.go | 2 - tools/url.go | 3 +- 52 files changed, 486 insertions(+), 502 deletions(-) diff --git a/.gitignore b/.gitignore index 7079750..14225c5 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ temp/ vendor config/settings.dev.yml go-admin +middleware/demo.go diff --git a/apis/monitor/server.go b/apis/monitor/server.go index 778498f..ab0ac20 100644 --- a/apis/monitor/server.go +++ b/apis/monitor/server.go @@ -47,7 +47,6 @@ func ServerInfo(c *gin.Context) { cpuDic := make(map[string]interface{}, 0) cpuDic["cpuNum"], _ = cpu.Counts(false) - app.Custum(c, gin.H{ "code": 200, "os": osDic, diff --git a/apis/system/config.go b/apis/system/config.go index 13b88a2..eca9515 100644 --- a/apis/system/config.go +++ b/apis/system/config.go @@ -86,7 +86,7 @@ func GetConfigByConfigKey(c *gin.Context) { result, err := Config.Get() tools.HasError(err, "抱歉未找到相关信息", -1) - app.OK(c, result,result.ConfigValue) + app.OK(c, result, result.ConfigValue) } // @Summary 添加配置 @@ -107,7 +107,7 @@ func InsertConfig(c *gin.Context) { result, err := data.Create() tools.HasError(err, "", -1) - app.OK(c, result,"") + app.OK(c, result, "") } // @Summary 修改配置 @@ -127,7 +127,7 @@ func UpdateConfig(c *gin.Context) { data.UpdateBy = tools.GetUserIdStr(c) result, err := data.Update(data.ConfigId) tools.HasError(err, "", -1) - app.OK(c, result,"") + app.OK(c, result, "") } // @Summary 删除配置 @@ -145,5 +145,3 @@ func DeleteConfig(c *gin.Context) { tools.HasError(err, "修改失败", 500) app.OK(c, result, msg.DeletedSuccess) } - - diff --git a/apis/system/dept.go b/apis/system/dept.go index 832ae34..2114aac 100644 --- a/apis/system/dept.go +++ b/apis/system/dept.go @@ -26,17 +26,17 @@ func GetDeptList(c *gin.Context) { Dept.DataScope = tools.GetUserIdStr(c) result, err := Dept.SetDept(true) tools.HasError(err, "抱歉未找到相关信息", -1) - app.OK(c,result,"") + app.OK(c, result, "") } func GetDeptTree(c *gin.Context) { var Dept models.SysDept Dept.DeptName = c.Request.FormValue("deptName") - Dept.Status= c.Request.FormValue("status") + Dept.Status = c.Request.FormValue("status") Dept.DeptId, _ = tools.StringToInt(c.Request.FormValue("deptId")) result, err := Dept.SetDept(false) tools.HasError(err, "抱歉未找到相关信息", -1) - app.OK(c,result,"") + app.OK(c, result, "") } // @Summary 部门列表数据 @@ -53,7 +53,7 @@ func GetDept(c *gin.Context) { Dept.DataScope = tools.GetUserIdStr(c) result, err := Dept.Get() tools.HasError(err, msg.NotFound, 404) - app.OK(c,result, msg.GetSuccess) + app.OK(c, result, msg.GetSuccess) } // @Summary 添加部门 @@ -73,7 +73,7 @@ func InsertDept(c *gin.Context) { data.CreateBy = tools.GetUserIdStr(c) result, err := data.Create() tools.HasError(err, "", -1) - app.OK(c,result, msg.CreatedSuccess) + app.OK(c, result, msg.CreatedSuccess) } // @Summary 修改部门 @@ -94,7 +94,7 @@ func UpdateDept(c *gin.Context) { data.UpdateBy = tools.GetUserIdStr(c) result, err := data.Update(data.DeptId) tools.HasError(err, "", -1) - app.OK(c,result, msg.UpdatedSuccess) + app.OK(c, result, msg.UpdatedSuccess) } // @Summary 删除部门 @@ -109,7 +109,7 @@ func DeleteDept(c *gin.Context) { id, err := tools.StringToInt(c.Param("id")) _, err = data.Delete(id) tools.HasError(err, "删除失败", 500) - app.OK(c,"", msg.DeletedSuccess) + app.OK(c, "", msg.DeletedSuccess) } func GetDeptTreeRoleselect(c *gin.Context) { @@ -124,7 +124,7 @@ func GetDeptTreeRoleselect(c *gin.Context) { menuIds, err = SysRole.GetRoleDeptId() tools.HasError(err, "抱歉未找到相关信息", -1) } - app.Custum(c,gin.H{ + app.Custum(c, gin.H{ "code": 200, "depts": result, "checkedKeys": menuIds, diff --git a/apis/system/dict/dictdata.go b/apis/system/dict/dictdata.go index a2bd8b0..f802fd5 100644 --- a/apis/system/dict/dictdata.go +++ b/apis/system/dict/dictdata.go @@ -148,5 +148,5 @@ func DeleteDictData(c *gin.Context) { IDS := tools.IdsStrToIdsIntGroup("dictCode", c) result, err := data.BatchDelete(IDS) tools.HasError(err, "修改失败", 500) - app.OK(c,result,"删除成功") + app.OK(c, result, "删除成功") } diff --git a/apis/system/index.go b/apis/system/index.go index 87d3b3e..5332706 100644 --- a/apis/system/index.go +++ b/apis/system/index.go @@ -1,6 +1,6 @@ package system -import( +import ( "github.com/gin-gonic/gin" ) @@ -33,8 +33,7 @@ $(function(){ ` - -func HelloWorld(c *gin.Context){ +func HelloWorld(c *gin.Context) { c.Header("Content-Type", "text/html; charset=utf-8") - c.String(200, INDEX) + c.String(200, INDEX) } diff --git a/apis/system/post.go b/apis/system/post.go index af1315d..112b9fa 100644 --- a/apis/system/post.go +++ b/apis/system/post.go @@ -54,7 +54,7 @@ func GetPost(c *gin.Context) { Post.PostId, _ = tools.StringToInt(c.Param("postId")) result, err := Post.Get() tools.HasError(err, "抱歉未找到相关信息", -1) - app.OK(c,result,"") + app.OK(c, result, "") } // @Summary 添加岗位 @@ -74,7 +74,7 @@ func InsertPost(c *gin.Context) { tools.HasError(err, "", 500) result, err := data.Create() tools.HasError(err, "", -1) - app.OK(c,result,"") + app.OK(c, result, "") } // @Summary 修改岗位 @@ -95,7 +95,7 @@ func UpdatePost(c *gin.Context) { tools.HasError(err, "", -1) result, err := data.Update(data.PostId) tools.HasError(err, "", -1) - app.OK(c,result,"修改成功") + app.OK(c, result, "修改成功") } // @Summary 删除岗位 @@ -111,5 +111,5 @@ func DeletePost(c *gin.Context) { IDS := tools.IdsStrToIdsIntGroup("postId", c) result, err := data.BatchDelete(IDS) tools.HasError(err, "删除失败", 500) - app.OK(c,result,"删除成功") + app.OK(c, result, "删除成功") } diff --git a/apis/tools/dbcolumns.go b/apis/tools/dbcolumns.go index 7219969..64b008b 100644 --- a/apis/tools/dbcolumns.go +++ b/apis/tools/dbcolumns.go @@ -31,7 +31,7 @@ func GetDBColumnList(c *gin.Context) { } data.TableName = c.Request.FormValue("tableName") - tools2.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) tools2.HasError(err, "", -1) diff --git a/apis/tools/gen.go b/apis/tools/gen.go index 81ae2db..df7840c 100644 --- a/apis/tools/gen.go +++ b/apis/tools/gen.go @@ -73,8 +73,8 @@ func GenCode(c *gin.Context) { _ = tools2.PathCreate("./apis/" + tab.ModuleName + "/") _ = tools2.PathCreate("./models/") _ = tools2.PathCreate("./router/") - _ = tools2.PathCreate(config.GenConfig.FrontPath+"/api/") - _ = tools2.PathCreate(config.GenConfig.FrontPath+"/views/"+tab.PackageName) + _ = tools2.PathCreate(config.GenConfig.FrontPath + "/api/") + _ = tools2.PathCreate(config.GenConfig.FrontPath + "/views/" + tab.PackageName) var b1 bytes.Buffer err = t1.Execute(&b1, tab) @@ -92,15 +92,15 @@ func GenCode(c *gin.Context) { tools2.FileCreate(b4, config.GenConfig.FrontPath+"/api/"+tab.PackageName+".js") tools2.FileCreate(b5, config.GenConfig.FrontPath+"/views/"+tab.PackageName+"/index.vue") - oldTest:="// {{认证路由自动补充在此处请勿删除}}" - newText:="// {{认证路由自动补充在此处请勿删除}} \r\n register"+tab.ClassName+"Router(v1,authMiddleware)" + oldTest := "// {{认证路由自动补充在此处请勿删除}}" + newText := "// {{认证路由自动补充在此处请勿删除}} \r\n register" + tab.ClassName + "Router(v1,authMiddleware)" helper := tools2.ReplaceHelper{ - Root: "./router/router.go", - OldText:oldTest, + Root: "./router/router.go", + OldText: oldTest, NewText: newText, } - if helper.OldText == helper.NewText{ + if helper.OldText == helper.NewText { log.Println("error !! the NewText isEqual the OldText") return } diff --git a/cmd/api/server.go b/cmd/api/server.go index fb65127..35aeff6 100644 --- a/cmd/api/server.go +++ b/cmd/api/server.go @@ -18,46 +18,46 @@ import ( "os" "os/signal" "time" - ) +) - var ( - configYml 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(&configYml, "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") +var ( + configYml 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 usage() { - usageStr := `starting api server` - log.Printf("%s\n", usageStr) - } +func init() { + StartCmd.PersistentFlags().StringVarP(&configYml, "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 setup() { - //1. 读取配置 - config.ConfigSetup(configYml) - //2. 设置日志 - tools.InitLogger() - //3. 初始化数据库链接 - database.Setup(config.DatabaseConfig.Driver) +func usage() { + usageStr := `starting api server` + log.Printf("%s\n", usageStr) +} - mycasbin.Setup() +func setup() { + //1. 读取配置 + config.ConfigSetup(configYml) + //2. 设置日志 + tools.InitLogger() + //3. 初始化数据库链接 + database.Setup(config.DatabaseConfig.Driver) + + mycasbin.Setup() } diff --git a/database/initialize.go b/database/initialize.go index 8e9c642..c377458 100644 --- a/database/initialize.go +++ b/database/initialize.go @@ -1,6 +1,5 @@ package database - func Setup(driver string) { dbType := driver if dbType == "mysql" { diff --git a/database/sqlite3-driver.go b/database/sqlite3-driver.go index bce5438..e41266d 100644 --- a/database/sqlite3-driver.go +++ b/database/sqlite3-driver.go @@ -47,4 +47,4 @@ func (e *SqLite) GetConnect() string { func (e *SqLite) GetDriver() string { return config.DatabaseConfig.Driver -} \ No newline at end of file +} diff --git a/global/adm.go b/global/adm.go index 1a15a4f..f9ad7e8 100644 --- a/global/adm.go +++ b/global/adm.go @@ -19,6 +19,6 @@ var CasbinEnforcer *casbin.Enforcer // go-admin Version Info var Version string -func init() { +func init() { Version = "1.0.10" -} \ No newline at end of file +} diff --git a/global/logger.go b/global/logger.go index f5ec10c..3e7246e 100644 --- a/global/logger.go +++ b/global/logger.go @@ -6,9 +6,7 @@ import ( var RequestLogger = &logrus.Entry{} - - -func init() { +func init() { // TODO: requestLogger log format // RequestLogger = logrus.WithFields(logrus.Fields{"request_id": request_id, "user_ip": user_ip}) -} \ No newline at end of file +} diff --git a/handler/ping.go b/handler/ping.go index 30a7373..ab4d645 100644 --- a/handler/ping.go +++ b/handler/ping.go @@ -8,4 +8,4 @@ func Ping(c *gin.Context) { c.JSON(200, gin.H{ "message": "ok", }) -} \ No newline at end of file +} diff --git a/handler/sd/check.go b/handler/sd/check.go index 9554b50..7b0622c 100644 --- a/handler/sd/check.go +++ b/handler/sd/check.go @@ -75,12 +75,12 @@ func DiskCheck(c *gin.Context) { func OSCheck(c *gin.Context) { status := http.StatusOK app.Custum(c, gin.H{ - "code": 200, - "status": status, - "goOs": runtime.GOOS, - "compiler": runtime.Compiler, - "numCpu": runtime.NumCPU(), - "version": runtime.Version(), + "code": 200, + "status": status, + "goOs": runtime.GOOS, + "compiler": runtime.Compiler, + "numCpu": runtime.NumCPU(), + "version": runtime.Version(), "numGoroutine": runtime.NumGoroutine(), }) } @@ -153,13 +153,12 @@ func RAMCheck(c *gin.Context) { text = "WARNING" } - app.Custum(c, gin.H{ - "code": 200, - "msg": text, - "status": status, - "used": usedMB, - "total": totalMB, - "usedPercent": usedPercent, + "code": 200, + "msg": text, + "status": status, + "used": usedMB, + "total": totalMB, + "usedPercent": usedPercent, }) } diff --git a/models/dictdata.go b/models/dictdata.go index 456126f..0ddf220 100644 --- a/models/dictdata.go +++ b/models/dictdata.go @@ -8,18 +8,18 @@ import ( type DictData struct { DictCode int `gorm:"primary_key;AUTO_INCREMENT" json:"dictCode" example:"1"` //字典编码 - DictSort int `gorm:"" json:"dictSort"` //显示顺序 - DictLabel string `gorm:"size:128;" json:"dictLabel"` //数据标签 - DictValue string `gorm:"size:255;" json:"dictValue"` //数据键值 - DictType string `gorm:"size:64;" json:"dictType"` //字典类型 - CssClass string `gorm:"size:128;" json:"cssClass"` // - ListClass string `gorm:"size:128;" json:"listClass"` // - IsDefault string `gorm:"size:8;" json:"isDefault"` // - Status string `gorm:"size:4;" json:"status"` //状态 - Default string `gorm:"size:8;" json:"default"` // - CreateBy string `gorm:"size:64;" json:"createBy"` // - UpdateBy string `gorm:"size:64;" json:"updateBy"` // - Remark string `gorm:"size:255;" json:"remark"` //备注 + DictSort int `gorm:"" json:"dictSort"` //显示顺序 + DictLabel string `gorm:"size:128;" json:"dictLabel"` //数据标签 + DictValue string `gorm:"size:255;" json:"dictValue"` //数据键值 + DictType string `gorm:"size:64;" json:"dictType"` //字典类型 + CssClass string `gorm:"size:128;" json:"cssClass"` // + ListClass string `gorm:"size:128;" json:"listClass"` // + IsDefault string `gorm:"size:8;" json:"isDefault"` // + Status string `gorm:"size:4;" json:"status"` //状态 + Default string `gorm:"size:8;" json:"default"` // + CreateBy string `gorm:"size:64;" json:"createBy"` // + UpdateBy string `gorm:"size:64;" json:"updateBy"` // + Remark string `gorm:"size:255;" json:"remark"` //备注 Params string `gorm:"-" json:"params"` DataScope string `gorm:"-" json:"dataScope"` BaseModel diff --git a/models/dicttype.go b/models/dicttype.go index 991d7c1..7bc5b46 100644 --- a/models/dicttype.go +++ b/models/dicttype.go @@ -10,9 +10,9 @@ type DictType struct { DictId int `gorm:"primary_key;AUTO_INCREMENT" json:"dictId"` DictName string `gorm:"size:128;" json:"dictName"` //字典名称 DictType string `gorm:"size:128;" json:"dictType"` //字典类型 - Status string `gorm:"size:4;" json:"status"` //状态 - DataScope string `gorm:"-" json:"dataScope"` // - Params string `gorm:"-" json:"params"` // + Status string `gorm:"size:4;" json:"status"` //状态 + DataScope string `gorm:"-" json:"dataScope"` // + Params string `gorm:"-" json:"params"` // CreateBy string `gorm:"size:11;" json:"createBy"` //创建者 UpdateBy string `gorm:"size:11;" json:"updateBy"` //更新者 Remark string `gorm:"size:255;" json:"remark"` //备注 diff --git a/models/loginlog.go b/models/loginlog.go index e614bd0..34c89ef 100644 --- a/models/loginlog.go +++ b/models/loginlog.go @@ -7,19 +7,19 @@ import ( type LoginLog struct { InfoId int `json:"infoId" gorm:"primary_key;AUTO_INCREMENT"` //主键 - Username string `json:"username" gorm:"size:128;"` //用户名 - Status string `json:"status" gorm:"size:4;"` //状态 - Ipaddr string `json:"ipaddr" gorm:"size:255;"` //ip地址 - LoginLocation string `json:"loginLocation" gorm:"size:255;"` //归属地 - Browser string `json:"browser" gorm:"size:255;"` //浏览器 - Os string `json:"os" gorm:"size:255;"` //系统 - Platform string `json:"platform" gorm:"size:255;"` // 固件 + Username string `json:"username" gorm:"size:128;"` //用户名 + Status string `json:"status" gorm:"size:4;"` //状态 + Ipaddr string `json:"ipaddr" gorm:"size:255;"` //ip地址 + LoginLocation string `json:"loginLocation" gorm:"size:255;"` //归属地 + Browser string `json:"browser" gorm:"size:255;"` //浏览器 + Os string `json:"os" gorm:"size:255;"` //系统 + Platform string `json:"platform" gorm:"size:255;"` // 固件 LoginTime time.Time `json:"loginTime" gorm:"type:timestamp;"` //登录时间 - CreateBy string `json:"createBy" gorm:"size:128;"` //创建人 - UpdateBy string `json:"updateBy" gorm:"size:128;"` //更新者 + CreateBy string `json:"createBy" gorm:"size:128;"` //创建人 + UpdateBy string `json:"updateBy" gorm:"size:128;"` //更新者 DataScope string `json:"dataScope" gorm:"-"` //数据 Params string `json:"params" gorm:"-"` // - Remark string `json:"remark" gorm:"size:255;"` //备注 + Remark string `json:"remark" gorm:"size:255;"` //备注 Msg string `json:"msg" gorm:"size:255;"` BaseModel } diff --git a/models/model.go b/models/model.go index 3974929..4a1c439 100644 --- a/models/model.go +++ b/models/model.go @@ -5,7 +5,7 @@ import ( ) type BaseModel struct { - CreatedAt time.Time `json:"createdAt"` - UpdatedAt time.Time `json:"updatedAt"` + CreatedAt time.Time `json:"createdAt"` + UpdatedAt time.Time `json:"updatedAt"` DeletedAt *time.Time `json:"deletedAt"` } diff --git a/models/operlog.go b/models/operlog.go index 93d50c9..d80e270 100644 --- a/models/operlog.go +++ b/models/operlog.go @@ -8,28 +8,28 @@ import ( //sys_operlog type SysOperLog struct { OperId int `json:"operId" gorm:"primary_key;AUTO_INCREMENT"` //日志编码 - Title string `json:"title" gorm:"size:255;"` //操作模块 - BusinessType string `json:"businessType" gorm:"size:128;"` //操作类型 + Title string `json:"title" gorm:"size:255;"` //操作模块 + BusinessType string `json:"businessType" gorm:"size:128;"` //操作类型 BusinessTypes string `json:"businessTypes" gorm:"size:128;"` - Method string `json:"method" gorm:"size:128;"` //函数 - RequestMethod string `json:"requestMethod" gorm:"size:128;"` //请求方式 - OperatorType string `json:"operatorType" gorm:"size:128;"` //操作类型 - OperName string `json:"operName" gorm:"size:128;"` //操作者 - DeptName string `json:"deptName" gorm:"size:128;"` //部门名称 - OperUrl string `json:"operUrl" gorm:"size:255;"` //访问地址 - OperIp string `json:"operIp" gorm:"size:128;"` //客户端ip - OperLocation string `json:"operLocation" gorm:"size:128;"` //访问位置 - OperParam string `json:"operParam" gorm:"size:255;"` //请求参数 - Status string `json:"status" gorm:"size:4;"` //操作状态 - OperTime time.Time `json:"operTime" gorm:"type:timestamp;"` //操作时间 - JsonResult string `json:"jsonResult" gorm:"size:255;"` //返回数据 - CreateBy string `json:"createBy" gorm:"size:128;"` //创建人 - UpdateBy string `json:"updateBy" gorm:"size:128;"` //更新者 - DataScope string `json:"dataScope" gorm:"-"` //数据 - Params string `json:"params" gorm:"-"` //参数 - Remark string `json:"remark" gorm:"size:255;"` //备注 - LatencyTime string `json:"latencyime" gorm:"size:128;"` //耗时 - UserAgent string `json:"userAgent" gorm:"size:255;"` //ua + Method string `json:"method" gorm:"size:128;"` //函数 + RequestMethod string `json:"requestMethod" gorm:"size:128;"` //请求方式 + OperatorType string `json:"operatorType" gorm:"size:128;"` //操作类型 + OperName string `json:"operName" gorm:"size:128;"` //操作者 + DeptName string `json:"deptName" gorm:"size:128;"` //部门名称 + OperUrl string `json:"operUrl" gorm:"size:255;"` //访问地址 + OperIp string `json:"operIp" gorm:"size:128;"` //客户端ip + OperLocation string `json:"operLocation" gorm:"size:128;"` //访问位置 + OperParam string `json:"operParam" gorm:"size:255;"` //请求参数 + Status string `json:"status" gorm:"size:4;"` //操作状态 + OperTime time.Time `json:"operTime" gorm:"type:timestamp;"` //操作时间 + JsonResult string `json:"jsonResult" gorm:"size:255;"` //返回数据 + CreateBy string `json:"createBy" gorm:"size:128;"` //创建人 + UpdateBy string `json:"updateBy" gorm:"size:128;"` //更新者 + DataScope string `json:"dataScope" gorm:"-"` //数据 + Params string `json:"params" gorm:"-"` //参数 + Remark string `json:"remark" gorm:"size:255;"` //备注 + LatencyTime string `json:"latencyime" gorm:"size:128;"` //耗时 + UserAgent string `json:"userAgent" gorm:"size:255;"` //ua BaseModel } diff --git a/models/post.go b/models/post.go index 426bb78..5d2c127 100644 --- a/models/post.go +++ b/models/post.go @@ -7,11 +7,11 @@ import ( type Post struct { PostId int `gorm:"primary_key;AUTO_INCREMENT" json:"postId"` //岗位编号 - PostName string `gorm:"size:128;" json:"postName"` //岗位名称 - PostCode string `gorm:"size:128;" json:"postCode"` //岗位代码 - Sort int `gorm:"" json:"sort"` //岗位排序 - Status string `gorm:"size:4;" json:"status"` //状态 - Remark string `gorm:"size:255;" json:"remark"` //描述 + PostName string `gorm:"size:128;" json:"postName"` //岗位名称 + PostCode string `gorm:"size:128;" json:"postCode"` //岗位代码 + Sort int `gorm:"" json:"sort"` //岗位排序 + Status string `gorm:"size:4;" json:"status"` //状态 + Remark string `gorm:"size:255;" json:"remark"` //描述 CreateBy string `gorm:"size:128;" json:"createBy"` UpdateBy string `gorm:"size:128;" json:"updateBy"` DataScope string `gorm:"-" json:"dataScope"` diff --git a/models/role.go b/models/role.go index f8bd97d..e96f62d 100644 --- a/models/role.go +++ b/models/role.go @@ -8,14 +8,14 @@ import ( type SysRole struct { RoleId int `json:"roleId" gorm:"primary_key;AUTO_INCREMENT"` // 角色编码 - RoleName string `json:"roleName" gorm:"size:128;"` // 角色名称 - Status string `json:"status" gorm:"size:4;"` // - RoleKey string `json:"roleKey" gorm:"size:128;"` //角色代码 - RoleSort int `json:"roleSort" gorm:""` //角色排序 - Flag string `json:"flag" gorm:"size:128;"` // - CreateBy string `json:"createBy" gorm:"size:128;"` // - UpdateBy string `json:"updateBy" gorm:"size:128;"` // - Remark string `json:"remark" gorm:"size:255;"` //备注 + RoleName string `json:"roleName" gorm:"size:128;"` // 角色名称 + Status string `json:"status" gorm:"size:4;"` // + RoleKey string `json:"roleKey" gorm:"size:128;"` //角色代码 + RoleSort int `json:"roleSort" gorm:""` //角色排序 + Flag string `json:"flag" gorm:"size:128;"` // + CreateBy string `json:"createBy" gorm:"size:128;"` // + UpdateBy string `json:"updateBy" gorm:"size:128;"` // + Remark string `json:"remark" gorm:"size:255;"` //备注 Admin bool `json:"admin" gorm:"size:4;"` DataScope string `json:"dataScope" gorm:"size:128;"` Params string `json:"params" gorm:"-"` @@ -52,7 +52,7 @@ func (role *SysRole) GetPage(pageSize int, pageIndex int) ([]SysRole, int, error // 数据权限控制 dataPermission := new(DataPermission) dataPermission.UserId, _ = tools.StringToInt(role.DataScope) - table,err := dataPermission.GetDataScope("sys_role", table) + table, err := dataPermission.GetDataScope("sys_role", table) if err != nil { return nil, 0, err } diff --git a/models/sysuser.go b/models/sysuser.go index 137b2eb..b373e94 100644 --- a/models/sysuser.go +++ b/models/sysuser.go @@ -42,13 +42,13 @@ type SysUserId struct { type SysUserB struct { NickName string `gorm:"size:128" json:"nickName"` // 昵称 Phone string `gorm:"size:11" json:"phone"` // 手机号 - RoleId int `gorm:"" json:"roleId"` // 角色编码 + RoleId int `gorm:"" json:"roleId"` // 角色编码 Salt string `gorm:"size:255" json:"salt"` //盐 Avatar string `gorm:"size:255" json:"avatar"` //头像 Sex string `gorm:"size:255" json:"sex"` //性别 Email string `gorm:"size:128" json:"email"` //邮箱 - DeptId int `gorm:"" json:"deptId"` //部门编码 - PostId int `gorm:"" json:"postId"` //职位编码 + DeptId int `gorm:"" json:"deptId"` //部门编码 + PostId int `gorm:"" json:"postId"` //职位编码 CreateBy string `gorm:"size:128" json:"createBy"` // UpdateBy string `gorm:"size:128" json:"updateBy"` // Remark string `gorm:"size:255" json:"remark"` //备注 @@ -59,7 +59,6 @@ type SysUserB struct { BaseModel } - type SysUser struct { SysUserId SysUserB diff --git a/models/tools/syscolumns.go b/models/tools/syscolumns.go index 914936e..50d4e3e 100644 --- a/models/tools/syscolumns.go +++ b/models/tools/syscolumns.go @@ -6,8 +6,8 @@ import ( ) type SysColumns struct { - ColumnId int `gorm:"primary_key;auto_increment" json:"columnId"` - TableId int `gorm:"" json:"tableId"` + ColumnId int `gorm:"primary_key;auto_increment" json:"columnId"` + TableId int `gorm:"" json:"tableId"` ColumnName string `gorm:"size:128;" json:"columnName"` ColumnComment string `gorm:"column:column_comment;size:128;" json:"columnComment"` ColumnType string `gorm:"column:column_type;size:128;" json:"columnType"` diff --git a/models/tools/systables.go b/models/tools/systables.go index b701137..baec3ae 100644 --- a/models/tools/systables.go +++ b/models/tools/systables.go @@ -6,7 +6,7 @@ import ( ) type SysTables struct { - TableId int `gorm:"primary_key;auto_increment" json:"tableId"` //表编码 + TableId int `gorm:"primary_key;auto_increment" json:"tableId"` //表编码 TBName string `gorm:"column:table_name;size:255;" json:"tableName"` //表名称 TableComment string `gorm:"size:255;" json:"tableComment"` //表备注 ClassName string `gorm:"size:255;" json:"className"` //类名 diff --git a/pkg/casbin/mycasbin.go b/pkg/casbin/mycasbin.go index 55d92e3..3140761 100644 --- a/pkg/casbin/mycasbin.go +++ b/pkg/casbin/mycasbin.go @@ -24,8 +24,6 @@ e = some(where (p.eft == allow)) m = r.sub == p.sub && (keyMatch2(r.obj, p.obj) || keyMatch(r.obj, p.obj)) && (r.act == p.act || p.act == "*") ` - - func Setup() { Apter, err := gormAdapter.NewAdapterByDB(global.Eloquent) if err != nil { diff --git a/pkg/logger/logger.go b/pkg/logger/logger.go index 4b27585..2f9711d 100644 --- a/pkg/logger/logger.go +++ b/pkg/logger/logger.go @@ -5,9 +5,7 @@ import ( ) var ( - Info *log.Logger + Info *log.Logger Warning *log.Logger - Error * log.Logger + Error *log.Logger ) - - diff --git a/router/router.go b/router/router.go index b6cca1a..9923e2e 100644 --- a/router/router.go +++ b/router/router.go @@ -7,8 +7,6 @@ import ( jwt "go-admin/pkg/jwtauth" ) - - // 路由示例 func InitExamplesRouter(r *gin.Engine, authMiddleware *jwt.GinJWTMiddleware) *gin.Engine { @@ -32,10 +30,7 @@ func examplesNoCheckRoleRouter(r *gin.Engine) { // 需要认证的路由示例 func examplesCheckRoleRouter(r *gin.Engine, authMiddleware *jwtauth.GinJWTMiddleware) { v1 := r.Group("/api/v1") - v1.GET("/checkrole",nil) + v1.GET("/checkrole", nil) // {{认证路由自动补充在此处请勿删除}} } - - - diff --git a/template/model.go.template b/template/model.go.template index b66b306..92bffea 100644 --- a/template/model.go.template +++ b/template/model.go.template @@ -7,119 +7,119 @@ _ "time" ) type {{.ClassName}} struct { - {{ range .Columns -}} +{{ range .Columns -}} {{$x := .Pk}} {{- if ($x) }} - {{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};primary_key"` // {{.ColumnComment}} + {{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};primary_key"` // {{.ColumnComment}} {{- else if eq .GoField "CreatedAt" -}} {{- else if eq .GoField "UpdatedAt" -}} {{- else if eq .GoField "DeletedAt" -}} {{- else }} - {{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};"` // {{.ColumnComment}}{{end -}} - {{- end }} - DataScope string `json:"dataScope" gorm:"-"` - Params string `json:"params" gorm:"-"` - BaseModel + {{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};"` // {{.ColumnComment}}{{end -}} +{{- end }} +DataScope string `json:"dataScope" gorm:"-"` +Params string `json:"params" gorm:"-"` +BaseModel } func ({{.ClassName}}) TableName() string { - return "{{.TBName}}" +return "{{.TBName}}" } // 创建{{.ClassName}} func (e *{{.ClassName}}) Create() ({{.ClassName}}, error) { - var doc {{.ClassName}} - result := orm.Eloquent.Table(e.TableName()).Create(&e) - if result.Error != nil { - err := result.Error - return doc, err - } - doc = *e - return doc, nil +var doc {{.ClassName}} +result := orm.Eloquent.Table(e.TableName()).Create(&e) +if result.Error != nil { +err := result.Error +return doc, err +} +doc = *e +return doc, nil } // 获取{{.ClassName}} func (e *{{.ClassName}}) Get() ({{.ClassName}}, error) { var doc {{.ClassName}} - table := orm.Eloquent.Table(e.TableName()) - {{ range .Columns }} +table := orm.Eloquent.Table(e.TableName()) +{{ range .Columns }} {{$x := .Pk}} {{- if ($x) }} - if e.{{.GoField}} != {{if eq .GoType "string" -}} "" {{ else if eq .GoType "int" -}} 0 {{- end}} { - table = table.Where("{{.ColumnName}}{{if eq .QueryType "EQ"}} = {{else if eq .QueryType "NE"}} != {{else if eq .QueryType "GT"}} > {{else if eq .QueryType "GTE"}} >= {{else if eq .QueryType "LT"}} < {{else if eq .QueryType "LTE"}} <= {{else if eq .QueryType "LIKE"}} like {{end}}?", {{ if eq .QueryType "LIKE"}}"%"+e.{{.GoField}}+"%"{{else}}e.{{.GoField}}{{end}}) - } - {{- else if .IsQuery }} - if e.{{.GoField}} != {{if eq .GoType "string" -}} "" {{ else if eq .GoType "int" -}} 0 {{- end}} { + if e.{{.GoField}} != {{if eq .GoType "string" -}} "" {{ else if eq .GoType "int" -}} 0 {{- end}} { table = table.Where("{{.ColumnName}}{{if eq .QueryType "EQ"}} = {{else if eq .QueryType "NE"}} != {{else if eq .QueryType "GT"}} > {{else if eq .QueryType "GTE"}} >= {{else if eq .QueryType "LT"}} < {{else if eq .QueryType "LTE"}} <= {{else if eq .QueryType "LIKE"}} like {{end}}?", {{ if eq .QueryType "LIKE"}}"%"+e.{{.GoField}}+"%"{{else}}e.{{.GoField}}{{end}}) - } + } + {{- else if .IsQuery }} + if e.{{.GoField}} != {{if eq .GoType "string" -}} "" {{ else if eq .GoType "int" -}} 0 {{- end}} { + table = table.Where("{{.ColumnName}}{{if eq .QueryType "EQ"}} = {{else if eq .QueryType "NE"}} != {{else if eq .QueryType "GT"}} > {{else if eq .QueryType "GTE"}} >= {{else if eq .QueryType "LT"}} < {{else if eq .QueryType "LTE"}} <= {{else if eq .QueryType "LIKE"}} like {{end}}?", {{ if eq .QueryType "LIKE"}}"%"+e.{{.GoField}}+"%"{{else}}e.{{.GoField}}{{end}}) + } {{ end -}} - {{- end }} +{{- end }} - if err := table.First(&doc).Error; err != nil { - return doc, err - } - return doc, nil +if err := table.First(&doc).Error; err != nil { +return doc, err +} +return doc, nil } // 获取{{.ClassName}}带分页 func (e *{{.ClassName}}) GetPage(pageSize int, pageIndex int) ([]{{.ClassName}}, int, error) { - var doc []{{.ClassName}} +var doc []{{.ClassName}} - table := orm.Eloquent.Select("*").Table(e.TableName()) - {{ range .Columns }} +table := orm.Eloquent.Select("*").Table(e.TableName()) +{{ range .Columns }} {{- if .IsQuery }} - if e.{{.GoField}} != {{if eq .GoType "string" -}} "" {{ else if eq .GoType "int" -}} 0 {{- end}} { + if e.{{.GoField}} != {{if eq .GoType "string" -}} "" {{ else if eq .GoType "int" -}} 0 {{- end}} { table = table.Where("{{.ColumnName}}{{if eq .QueryType "EQ"}} = {{else if eq .QueryType "NE"}} != {{else if eq .QueryType "GT"}} > {{else if eq .QueryType "GTE"}} >= {{else if eq .QueryType "LT"}} < {{else if eq .QueryType "LTE"}} <= {{else if eq .QueryType "LIKE"}} like {{end}}?", {{ if eq .QueryType "LIKE"}}"%"+e.{{.GoField}}+"%"{{else}}e.{{.GoField}}{{end}}) - } + } {{ end -}} - {{- end }} +{{- end }} - // 数据权限控制(如果不需要数据权限请将此处去掉) - dataPermission := new(DataPermission) - dataPermission.UserId, _ = tools.StringToInt(e.DataScope) - table,err := dataPermission.GetDataScope(e.TableName(), table) - if err != nil { - return nil, 0, err - } - var count int +// 数据权限控制(如果不需要数据权限请将此处去掉) +dataPermission := new(DataPermission) +dataPermission.UserId, _ = tools.StringToInt(e.DataScope) +table,err := dataPermission.GetDataScope(e.TableName(), table) +if err != nil { +return nil, 0, err +} +var count int - if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil { - return nil, 0, err - } - table.Where("`deleted_at` IS NULL").Count(&count) - return doc, count, nil +if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil { +return nil, 0, err +} +table.Where("`deleted_at` IS NULL").Count(&count) +return doc, count, nil } // 更新{{.ClassName}} func (e *{{.ClassName}}) Update(id int) (update {{.ClassName}}, err error) { - if err = orm.Eloquent.Table(e.TableName()).Where("{{.PkColumn}} = ?", id).First(&update).Error; err != nil { - return - } +if err = orm.Eloquent.Table(e.TableName()).Where("{{.PkColumn}} = ?", id).First(&update).Error; err != nil { +return +} - //参数1:是要修改的数据 - //参数2:是修改的数据 - if err = orm.Eloquent.Table(e.TableName()).Model(&update).Updates(&e).Error; err != nil { - return - } - return +//参数1:是要修改的数据 +//参数2:是修改的数据 +if err = orm.Eloquent.Table(e.TableName()).Model(&update).Updates(&e).Error; err != nil { +return +} +return } // 删除{{.ClassName}} func (e *{{.ClassName}}) Delete(id int) (success bool, err error) { - if err = orm.Eloquent.Table(e.TableName()).Where("{{.PkColumn}} = ?", id).Delete(&{{.ClassName}}{}).Error; err != nil { - success = false - return - } - success = true - return +if err = orm.Eloquent.Table(e.TableName()).Where("{{.PkColumn}} = ?", id).Delete(&{{.ClassName}}{}).Error; err != nil { +success = false +return +} +success = true +return } //批量删除 func (e *{{.ClassName}}) BatchDelete(id []int) (Result bool, err error) { - if err = orm.Eloquent.Table(e.TableName()).Where("{{.PkColumn}} in (?)", id).Delete(&{{.ClassName}}{}).Error; err != nil { - return - } - Result = true - return +if err = orm.Eloquent.Table(e.TableName()).Where("{{.PkColumn}} in (?)", id).Delete(&{{.ClassName}}{}).Error; err != nil { +return +} +Result = true +return } diff --git a/template/router.go.template b/template/router.go.template index 5ef781f..b2ace7a 100644 --- a/template/router.go.template +++ b/template/router.go.template @@ -1,10 +1,10 @@ package router import ( - "github.com/gin-gonic/gin" - "go-admin/middleware" - "go-admin/apis/{{.ModuleName}}" - jwt "go-admin/pkg/jwtauth" +"github.com/gin-gonic/gin" +"go-admin/middleware" +"go-admin/apis/{{.ModuleName}}" +jwt "go-admin/pkg/jwtauth" ) // 需认证的路由代码 diff --git a/template/vue.go.template b/template/vue.go.template index a44989f..92994a9 100644 --- a/template/vue.go.template +++ b/template/vue.go.template @@ -3,23 +3,25 @@
{{range .Columns}} - {{- $x := .IsQuery -}} - {{- if ($x) -}} - - {{if eq .DictType "" -}} - - {{- else -}} - - - - {{- end}} - - {{end}} + {{- $x := .IsQuery -}} + {{- if ($x) -}} + + {{if eq .DictType "" -}} + + {{- else -}} + + + + {{- end}} + + {{end}} {{- end }} 搜索 @@ -35,7 +37,8 @@ icon="el-icon-plus" size="mini" @click="handleAdd" - >新增 + >新增 + 修改 + >修改 + 删除 + >删除 + - + {{- range .Columns -}} - {{- $x := .IsList -}} - {{- if ($x) }} - {{- if ne .DictType "" -}} - - - - {{- end -}} - {{- if eq .DictType "" -}} - - {{- end -}} + {{- $x := .IsList -}} + {{- if ($x) }} + {{- if ne .DictType "" -}} + + + + {{- end -}} + {{- if eq .DictType "" -}} + + {{- end -}} - {{- end }} + {{- end }} {{- end }} @@ -109,36 +118,38 @@ {{ range .Columns }} - {{- $x := .IsInsert -}} - {{- if ($x) -}} - {{- if (.Pk) }} - {{- else if eq .GoField "CreatedAt" -}} - {{- else if eq .GoField "UpdatedAt" -}} - {{- else if eq .GoField "DeletedAt" -}} - {{- else if eq .GoField "UpdateBy" -}} - {{- else if eq .GoField "CreateBy" -}} - {{- else }} - - {{ if eq "input" .HtmlType -}} - - {{- else if eq "select" .HtmlType -}} - - - - - {{- else if eq "radio" .HtmlType -}} - - {{"{{"}} dict.dictLabel {{"}}"}} - - {{- end }} - + {{- $x := .IsInsert -}} + {{- if ($x) -}} + {{- if (.Pk) }} + {{- else if eq .GoField "CreatedAt" -}} + {{- else if eq .GoField "UpdatedAt" -}} + {{- else if eq .GoField "DeletedAt" -}} + {{- else if eq .GoField "UpdateBy" -}} + {{- else if eq .GoField "CreateBy" -}} + {{- else }} + + {{ if eq "input" .HtmlType -}} + + {{- else if eq "select" .HtmlType -}} + + + + + {{- else if eq "radio" .HtmlType -}} + + {{"{{"}} dict.dictLabel {{"}}"}} + + {{- end }} + + {{- end }} {{- end }} {{- end }} - {{- end }}