Browse Source

Merge pull request #560 from iiiusky/fix/commentStyle

修改模板中的注释格式为官方推荐的格式
main
奇淼(piexlmax 3 years ago
committed by GitHub
parent
commit
7a1c2abfe8
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      server/resource/template/server/api.go.tpl
  2. 2
      server/resource/template/server/model.go.tpl
  3. 1
      server/resource/template/server/router.go.tpl
  4. 48
      server/resource/template/server/service.go.tpl

6
server/resource/template/server/api.go.tpl

@ -10,6 +10,7 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
) )
// Create{{.StructName}} 创建{{.StructName}}
// @Tags {{.StructName}} // @Tags {{.StructName}}
// @Summary 创建{{.StructName}} // @Summary 创建{{.StructName}}
// @Security ApiKeyAuth // @Security ApiKeyAuth
@ -29,6 +30,7 @@ func Create{{.StructName}}(c *gin.Context) {
} }
} }
// Delete{{.StructName}} 删除{{.StructName}}
// @Tags {{.StructName}} // @Tags {{.StructName}}
// @Summary 删除{{.StructName}} // @Summary 删除{{.StructName}}
// @Security ApiKeyAuth // @Security ApiKeyAuth
@ -48,6 +50,7 @@ func Delete{{.StructName}}(c *gin.Context) {
} }
} }
// Delete{{.StructName}}ByIds 批量删除{{.StructName}}
// @Tags {{.StructName}} // @Tags {{.StructName}}
// @Summary 批量删除{{.StructName}} // @Summary 批量删除{{.StructName}}
// @Security ApiKeyAuth // @Security ApiKeyAuth
@ -67,6 +70,7 @@ func Delete{{.StructName}}ByIds(c *gin.Context) {
} }
} }
// Update{{.StructName}} 更新{{.StructName}}
// @Tags {{.StructName}} // @Tags {{.StructName}}
// @Summary 更新{{.StructName}} // @Summary 更新{{.StructName}}
// @Security ApiKeyAuth // @Security ApiKeyAuth
@ -86,6 +90,7 @@ func Update{{.StructName}}(c *gin.Context) {
} }
} }
// Find{{.StructName}} 用id查询{{.StructName}}
// @Tags {{.StructName}} // @Tags {{.StructName}}
// @Summary 用id查询{{.StructName}} // @Summary 用id查询{{.StructName}}
// @Security ApiKeyAuth // @Security ApiKeyAuth
@ -105,6 +110,7 @@ func Find{{.StructName}}(c *gin.Context) {
} }
} }
// Get{{.StructName}}List 分页获取{{.StructName}}列表
// @Tags {{.StructName}} // @Tags {{.StructName}}
// @Summary 分页获取{{.StructName}}列表 // @Summary 分页获取{{.StructName}}列表
// @Security ApiKeyAuth // @Security ApiKeyAuth

2
server/resource/template/server/model.go.tpl

@ -5,6 +5,7 @@ import (
"gin-vue-admin/global" "gin-vue-admin/global"
) )
// {{.StructName}} 结构体
// 如果含有time.Time 请自行import time包 // 如果含有time.Time 请自行import time包
type {{.StructName}} struct { type {{.StructName}} struct {
global.GVA_MODEL {{- range .Fields}} global.GVA_MODEL {{- range .Fields}}
@ -16,6 +17,7 @@ type {{.StructName}} struct {
} }
{{ if .TableName }} {{ if .TableName }}
// TableName {{.StructName}} 表名
func ({{.StructName}}) TableName() string { func ({{.StructName}}) TableName() string {
return "{{.TableName}}" return "{{.TableName}}"
} }

1
server/resource/template/server/router.go.tpl

@ -6,6 +6,7 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
// Init{{.StructName}}Router 初始化 {{.StructName}} 路由信息
func Init{{.StructName}}Router(Router *gin.RouterGroup) { func Init{{.StructName}}Router(Router *gin.RouterGroup) {
{{.StructName}}Router := Router.Group("{{.Abbreviation}}").Use(middleware.OperationRecord()) {{.StructName}}Router := Router.Group("{{.Abbreviation}}").Use(middleware.OperationRecord())
{ {

48
server/resource/template/server/service.go.tpl

@ -6,67 +6,43 @@ import (
"gin-vue-admin/model/request" "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)
func Create{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error) { func Create{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error) {
err = global.GVA_DB.Create(&{{.Abbreviation}}).Error err = global.GVA_DB.Create(&{{.Abbreviation}}).Error
return err 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)
func Delete{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error) { func Delete{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error) {
err = global.GVA_DB.Delete(&{{.Abbreviation}}).Error err = global.GVA_DB.Delete(&{{.Abbreviation}}).Error
return err 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)
func Delete{{.StructName}}ByIds(ids request.IdsReq) (err error) { func Delete{{.StructName}}ByIds(ids request.IdsReq) (err error) {
err = global.GVA_DB.Delete(&[]model.{{.StructName}}{},"id in ?",ids.Ids).Error err = global.GVA_DB.Delete(&[]model.{{.StructName}}{},"id in ?",ids.Ids).Error
return err 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)
func Update{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error) { func Update{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error) {
err = global.GVA_DB.Save(&{{.Abbreviation}}).Error err = global.GVA_DB.Save(&{{.Abbreviation}}).Error
return err 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)
func Get{{.StructName}}(id uint) (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 err = global.GVA_DB.Where("id = ?", id).First(&{{.Abbreviation}}).Error
return 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)
func Get{{.StructName}}InfoList(info request.{{.StructName}}Search) (err error, list interface{}, total int64) { func Get{{.StructName}}InfoList(info request.{{.StructName}}Search) (err error, list interface{}, total int64) {
limit := info.PageSize limit := info.PageSize
offset := info.PageSize * (info.Page - 1) offset := info.PageSize * (info.Page - 1)

Loading…
Cancel
Save