// ========================================================================== // GFast自动生成api操作代码。 // 生成日期:{{date "Y-m-d H:i:s"}} // 生成路径: api/v1/{{.table.ModuleName }}/{{.table.TableName}}.go // 生成人:{{.table.FunctionAuthor}} // desc:{{.table.FunctionName}}相关参数 // company:云南奇讯科技有限公司 // ========================================================================== //// package {{.table.ModuleName }} //// {{$hasUpFile:=false}} {{$hasArr:=false}} {{range $index,$column :=.table.Columns}} {{if eq $column.HtmlType "imagefile" "images" "file" "files" }} {{$hasUpFile = true}} {{end}} {{if eq $column.HtmlType "checkbox"}} {{$hasArr = true}} {{end}} {{end}} import ( {{if $hasArr}} "github.com/gogf/gf/v2/container/garray" {{end}} "github.com/gogf/gf/v2/frame/g" {{if .table.HasTimeColumn}} "github.com/gogf/gf/v2/os/gtime" {{end}} commonApi "{{.goModName}}/api/v1/common" {{if $hasUpFile}} comModel "{{.goModName}}/internal/app/common/model" {{end}} "{{.goModName}}/{{.table.PackageName}}/model" ) // {{.table.ClassName}}SearchReq 分页请求参数 type {{.table.ClassName}}SearchReq struct { g.Meta `path:"/list" tags:"{{$.table.FunctionName}}" method:"get" summary:"{{$.table.FunctionName}}列表"` {{range $index, $column := .table.QueryColumns}} {{$column.GoField}} {{if or (eq $column.GoType "Time") (eq $column.GoType "int") (eq $column.GoType "int64") (eq $column.GoType "uint") (eq $column.GoType "uint64") (eq $column.GoType "float") (eq $column.GoType "float64") (eq $column.GoType "bool")}}{{if eq $column.QueryType "BETWEEN"}}[]{{end}}string{{else}}{{if eq $column.QueryType "BETWEEN"}}[]{{end}}{{$column.GoType}}{{end}} `p:"{{$column.HtmlField}}"{{if ne $column.FieldValidation ""}} v:"{{$column.FieldValidation}}"{{end}}` //{{$column.ColumnComment}} {{end}} commonApi.PageReq commonApi.Author } // {{.table.ClassName}}SearchRes 列表返回结果 type {{.table.ClassName}}SearchRes struct { g.Meta `mime:"application/json"` commonApi.ListRes List []*model.{{.table.ClassName}}ListRes `json:"list"` } // {{.table.ClassName}}AddReq 添加操作请求参数 type {{.table.ClassName}}AddReq struct { g.Meta `path:"/add" tags:"{{$.table.FunctionName}}" method:"post" summary:"{{$.table.FunctionName}}添加"` commonApi.Author {{if .table.IsPkInsertable}} {{.table.PkColumn.GoField}} {{.table.PkColumn.GoType}} `p:"{{.table.PkColumn.HtmlField}}" v:"required#主键ID不能为空"` {{end}} {{range $index, $column := .table.EditColumns}} {{$column.GoField}} {{if eq $column.GoType "Time"}}*gtime.Time{{else if eq $column.HtmlType "images" "file" "files"}}[]*comModel.UpFile{{else if eq $column.HtmlType "checkbox"}}garray.StrArray{{else}}{{$column.GoType}}{{end}} `p:"{{$column.HtmlField}}" {{if $column.IsRequired}}v:"required#{{$column.ColumnComment}}不能为空"{{end}}` {{end}} {{if .table.HasCreatedBy}} CreatedBy uint64 {{end}} } // {{.table.ClassName}}AddRes 添加操作返回结果 type {{.table.ClassName}}AddRes struct { commonApi.EmptyRes } // {{.table.ClassName}}EditReq 修改操作请求参数 type {{.table.ClassName}}EditReq struct { g.Meta `path:"/edit" tags:"{{$.table.FunctionName}}" method:"put" summary:"{{$.table.FunctionName}}修改"` commonApi.Author {{.table.PkColumn.GoField}} {{.table.PkColumn.GoType}} `p:"{{.table.PkColumn.HtmlField}}" v:"required#主键ID不能为空"` {{range $index, $column := .table.EditColumns}} {{$column.GoField}} {{if eq $column.GoType "Time"}}*gtime.Time{{else if eq $column.HtmlType "images" "file" "files"}}[]*comModel.UpFile{{else if eq $column.HtmlType "checkbox"}}garray.StrArray{{else}}{{$column.GoType}}{{end}} `p:"{{$column.HtmlField}}" {{if $column.IsRequired}}v:"required#{{$column.ColumnComment}}不能为空"{{end}}` {{end}} {{if .table.HasUpdatedBy}} UpdatedBy uint64 {{end}} } // {{.table.ClassName}}EditRes 修改操作返回结果 type {{.table.ClassName}}EditRes struct { commonApi.EmptyRes } // {{.table.ClassName}}GetReq 获取一条数据请求 type {{.table.ClassName}}GetReq struct { g.Meta `path:"/get" tags:"{{$.table.FunctionName}}" method:"get" summary:"获取{{$.table.FunctionName}}信息"` commonApi.Author {{$.table.PkColumn.GoField}} {{$.table.PkColumn.GoType}} `p:"{{$.table.PkColumn.HtmlField}}" v:"required#主键必须"` //通过主键获取 } // {{.table.ClassName}}GetRes 获取一条数据结果 type {{.table.ClassName}}GetRes struct { g.Meta `mime:"application/json"` *model.{{.table.ClassName}}InfoRes } // {{.table.ClassName}}DeleteReq 删除数据请求 type {{.table.ClassName}}DeleteReq struct { g.Meta `path:"/delete" tags:"{{$.table.FunctionName}}" method:"delete" summary:"删除{{$.table.FunctionName}}"` commonApi.Author {{$.table.PkColumn.GoField}}s []{{$.table.PkColumn.GoType}} `p:"{{$.table.PkColumn.HtmlField}}s" v:"required#主键必须"` //通过主键删除 } // {{.table.ClassName}}DeleteRes 删除数据返回 type {{.table.ClassName}}DeleteRes struct { commonApi.EmptyRes }