From dfe513192675121704e0ba6c41d47665bab2ca82 Mon Sep 17 00:00:00 2001 From: sky Date: Fri, 2 Jul 2021 15:22:13 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E6=B3=A8=E9=87=8A=E6=A0=BC=E5=BC=8F=E4=B8=BA?= =?UTF-8?q?=E5=AE=98=E6=96=B9=E6=8E=A8=E8=8D=90=E7=9A=84=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?.https://github.com/golang/go/wiki/CodeReviewComments#comment-s?= =?UTF-8?q?entences?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/resource/template/server/api.go.tpl | 6 ++ server/resource/template/server/model.go.tpl | 2 + server/resource/template/server/router.go.tpl | 1 + .../resource/template/server/service.go.tpl | 72 +++++++++---------- 4 files changed, 45 insertions(+), 36 deletions(-) diff --git a/server/resource/template/server/api.go.tpl b/server/resource/template/server/api.go.tpl index 9df3e153..0ab3dea7 100644 --- a/server/resource/template/server/api.go.tpl +++ b/server/resource/template/server/api.go.tpl @@ -10,6 +10,7 @@ import ( "go.uber.org/zap" ) +// Create{{.StructName}} 创建{{.StructName}} // @Tags {{.StructName}} // @Summary 创建{{.StructName}} // @Security ApiKeyAuth @@ -29,6 +30,7 @@ func Create{{.StructName}}(c *gin.Context) { } } +// Delete{{.StructName}} 删除{{.StructName}} // @Tags {{.StructName}} // @Summary 删除{{.StructName}} // @Security ApiKeyAuth @@ -48,6 +50,7 @@ func Delete{{.StructName}}(c *gin.Context) { } } +// Delete{{.StructName}}ByIds 批量删除{{.StructName}} // @Tags {{.StructName}} // @Summary 批量删除{{.StructName}} // @Security ApiKeyAuth @@ -67,6 +70,7 @@ func Delete{{.StructName}}ByIds(c *gin.Context) { } } +// Update{{.StructName}} 更新{{.StructName}} // @Tags {{.StructName}} // @Summary 更新{{.StructName}} // @Security ApiKeyAuth @@ -86,6 +90,7 @@ func Update{{.StructName}}(c *gin.Context) { } } +// Find{{.StructName}} 用id查询{{.StructName}} // @Tags {{.StructName}} // @Summary 用id查询{{.StructName}} // @Security ApiKeyAuth @@ -105,6 +110,7 @@ func Find{{.StructName}}(c *gin.Context) { } } +// Get{{.StructName}}List 分页获取{{.StructName}}列表 // @Tags {{.StructName}} // @Summary 分页获取{{.StructName}}列表 // @Security ApiKeyAuth diff --git a/server/resource/template/server/model.go.tpl b/server/resource/template/server/model.go.tpl index bbc7331b..b0b14e83 100644 --- a/server/resource/template/server/model.go.tpl +++ b/server/resource/template/server/model.go.tpl @@ -5,6 +5,7 @@ import ( "gin-vue-admin/global" ) +// {{.StructName}} 结构体 // 如果含有time.Time 请自行import time包 type {{.StructName}} struct { global.GVA_MODEL {{- range .Fields}} @@ -16,6 +17,7 @@ type {{.StructName}} struct { } {{ if .TableName }} +// TableName {{.StructName}} 表名 func ({{.StructName}}) TableName() string { return "{{.TableName}}" } diff --git a/server/resource/template/server/router.go.tpl b/server/resource/template/server/router.go.tpl index 87c41885..0e649589 100644 --- a/server/resource/template/server/router.go.tpl +++ b/server/resource/template/server/router.go.tpl @@ -6,6 +6,7 @@ import ( "github.com/gin-gonic/gin" ) +// Init{{.StructName}}Router 初始化 {{.StructName}} 路由信息 func Init{{.StructName}}Router(Router *gin.RouterGroup) { {{.StructName}}Router := Router.Group("{{.Abbreviation}}").Use(middleware.OperationRecord()) { diff --git a/server/resource/template/server/service.go.tpl b/server/resource/template/server/service.go.tpl index 323f7956..b9b5111f 100644 --- a/server/resource/template/server/service.go.tpl +++ b/server/resource/template/server/service.go.tpl @@ -6,67 +6,67 @@ import ( "gin-vue-admin/model/request" ) -//@author: [piexlmax](https://github.com/piexlmax) -//@function: Create{{.StructName}} -//@description: 创建{{.StructName}}记录 -//@param: {{.Abbreviation}} model.{{.StructName}} -//@return: err error - +// Create{{.StructName}} 创建{{.StructName}}记录 +// @author: [piexlmax](https://github.com/piexlmax) +// @function: Create{{.StructName}} +// @description: 创建{{.StructName}}记录 +// @param: {{.Abbreviation}} model.{{.StructName}} +// @return: err error func Create{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error) { err = global.GVA_DB.Create(&{{.Abbreviation}}).Error return err } -//@author: [piexlmax](https://github.com/piexlmax) -//@function: Delete{{.StructName}} -//@description: 删除{{.StructName}}记录 -//@param: {{.Abbreviation}} model.{{.StructName}} -//@return: err error - +// Delete{{.StructName}} 删除{{.StructName}}记录 +// @author: [piexlmax](https://github.com/piexlmax) +// @function: Delete{{.StructName}} +// @description: 删除{{.StructName}}记录 +// @param: {{.Abbreviation}} model.{{.StructName}} +// @return: err error func Delete{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error) { err = global.GVA_DB.Delete(&{{.Abbreviation}}).Error return err } -//@author: [piexlmax](https://github.com/piexlmax) -//@function: Delete{{.StructName}}ByIds -//@description: 批量删除{{.StructName}}记录 -//@param: ids request.IdsReq -//@return: err error - +// Delete{{.StructName}}ByIds 批量删除{{.StructName}}记录 +// @author: [piexlmax](https://github.com/piexlmax) +// @function: Delete{{.StructName}}ByIds +// @description: 批量删除{{.StructName}}记录 +// @param: ids request.IdsReq +// @return: err error func Delete{{.StructName}}ByIds(ids request.IdsReq) (err error) { err = global.GVA_DB.Delete(&[]model.{{.StructName}}{},"id in ?",ids.Ids).Error return err } -//@author: [piexlmax](https://github.com/piexlmax) -//@function: Update{{.StructName}} -//@description: 更新{{.StructName}}记录 -//@param: {{.Abbreviation}} *model.{{.StructName}} -//@return: err error - +// Update{{.StructName}} 更新{{.StructName}}记录 +// @author: [piexlmax](https://github.com/piexlmax) +// @function: Update{{.StructName}} +// @description: 更新{{.StructName}}记录 +// @param: {{.Abbreviation}} *model.{{.StructName}} +// @return: err error func Update{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error) { err = global.GVA_DB.Save(&{{.Abbreviation}}).Error return err } -//@author: [piexlmax](https://github.com/piexlmax) -//@function: Get{{.StructName}} -//@description: 根据id获取{{.StructName}}记录 -//@param: id uint -//@return: err error, {{.Abbreviation}} model.{{.StructName}} - +// Get{{.StructName}} 根据id获取{{.StructName}}记录 +// @author: [piexlmax](https://github.com/piexlmax) +// @function: Get{{.StructName}} +// @description: 根据id获取{{.StructName}}记录 +// @param: id uint +// @return: err error, {{.Abbreviation}} model.{{.StructName}} func Get{{.StructName}}(id uint) (err error, {{.Abbreviation}} model.{{.StructName}}) { err = global.GVA_DB.Where("id = ?", id).First(&{{.Abbreviation}}).Error return } -//@author: [piexlmax](https://github.com/piexlmax) -//@function: Get{{.StructName}}InfoList -//@description: 分页获取{{.StructName}}记录 -//@param: info request.{{.StructName}}Search -//@return: err error, list interface{}, total int64 - +// Get{{.StructName}}InfoList 分页获取{{.StructName}}记录 +// @author: [piexlmax](https://github.com/piexlmax) +// @function: Get{{.StructName}}InfoList +// @description: 分页获取{{.StructName}}记录 +// @param: info request.{{.StructName}}Search +// @return: err error, list interface{}, total int64 func Get{{.StructName}}InfoList(info request.{{.StructName}}Search) (err error, list interface{}, total int64) { limit := info.PageSize offset := info.PageSize * (info.Page - 1) From f77d6b92094b555e35f2271e72aa1aeb84164acc Mon Sep 17 00:00:00 2001 From: SliverHorn <45428434+SliverHorn@users.noreply.github.com> Date: Fri, 2 Jul 2021 17:18:51 +0800 Subject: [PATCH 2/2] Update service.go.tpl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 回参与入参,我觉得可以去掉,基本调用的时候都知道是什么类型,就没必要写了 --- .../resource/template/server/service.go.tpl | 38 ++++--------------- 1 file changed, 7 insertions(+), 31 deletions(-) diff --git a/server/resource/template/server/service.go.tpl b/server/resource/template/server/service.go.tpl index b9b5111f..b1da36c5 100644 --- a/server/resource/template/server/service.go.tpl +++ b/server/resource/template/server/service.go.tpl @@ -7,66 +7,42 @@ import ( ) // Create{{.StructName}} 创建{{.StructName}}记录 -// @author: [piexlmax](https://github.com/piexlmax) -// @function: Create{{.StructName}} -// @description: 创建{{.StructName}}记录 -// @param: {{.Abbreviation}} model.{{.StructName}} -// @return: err error +// Author [piexlmax](https://github.com/piexlmax) func Create{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error) { err = global.GVA_DB.Create(&{{.Abbreviation}}).Error return err } // Delete{{.StructName}} 删除{{.StructName}}记录 -// @author: [piexlmax](https://github.com/piexlmax) -// @function: Delete{{.StructName}} -// @description: 删除{{.StructName}}记录 -// @param: {{.Abbreviation}} model.{{.StructName}} -// @return: err error +// Author [piexlmax](https://github.com/piexlmax) func Delete{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error) { err = global.GVA_DB.Delete(&{{.Abbreviation}}).Error return err } // Delete{{.StructName}}ByIds 批量删除{{.StructName}}记录 -// @author: [piexlmax](https://github.com/piexlmax) -// @function: Delete{{.StructName}}ByIds -// @description: 批量删除{{.StructName}}记录 -// @param: ids request.IdsReq -// @return: err error +// Author [piexlmax](https://github.com/piexlmax) func Delete{{.StructName}}ByIds(ids request.IdsReq) (err error) { err = global.GVA_DB.Delete(&[]model.{{.StructName}}{},"id in ?",ids.Ids).Error return err } // Update{{.StructName}} 更新{{.StructName}}记录 -// @author: [piexlmax](https://github.com/piexlmax) -// @function: Update{{.StructName}} -// @description: 更新{{.StructName}}记录 -// @param: {{.Abbreviation}} *model.{{.StructName}} -// @return: err error +// Author [piexlmax](https://github.com/piexlmax) func Update{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error) { err = global.GVA_DB.Save(&{{.Abbreviation}}).Error return err } // Get{{.StructName}} 根据id获取{{.StructName}}记录 -// @author: [piexlmax](https://github.com/piexlmax) -// @function: Get{{.StructName}} -// @description: 根据id获取{{.StructName}}记录 -// @param: id uint -// @return: err error, {{.Abbreviation}} model.{{.StructName}} +// Author [piexlmax](https://github.com/piexlmax) func Get{{.StructName}}(id uint) (err error, {{.Abbreviation}} model.{{.StructName}}) { err = global.GVA_DB.Where("id = ?", id).First(&{{.Abbreviation}}).Error return } // Get{{.StructName}}InfoList 分页获取{{.StructName}}记录 -// @author: [piexlmax](https://github.com/piexlmax) -// @function: Get{{.StructName}}InfoList -// @description: 分页获取{{.StructName}}记录 -// @param: info request.{{.StructName}}Search -// @return: err error, list interface{}, total int64 +// Author [piexlmax](https://github.com/piexlmax) func Get{{.StructName}}InfoList(info request.{{.StructName}}Search) (err error, list interface{}, total int64) { limit := info.PageSize offset := info.PageSize * (info.Page - 1) @@ -102,4 +78,4 @@ func Get{{.StructName}}InfoList(info request.{{.StructName}}Search) (err error, err = db.Count(&total).Error err = db.Limit(limit).Offset(offset).Find(&{{.Abbreviation}}s).Error return err, {{.Abbreviation}}s, total -} \ No newline at end of file +}