github.com/unionj-cloud/go-doudou/v2@v2.3.5/toolkit/gormgen/internal/template/model.go (about) 1 package template 2 3 // Model used as a variable because it cannot load template file after packed, params still can pass file 4 const Model = NotEditMark + ` 5 package {{.StructInfo.Package}} 6 7 import ( 8 "{{.ConfigPackage}}" 9 "fmt" 10 "github.com/unionj-cloud/go-doudou/v2/toolkit/stringutils" 11 12 "encoding/json" 13 "time" 14 15 "gorm.io/datatypes" 16 "gorm.io/gorm" 17 "gorm.io/gorm/schema" 18 {{range .ImportPkgPaths}}{{.}} ` + "\n" + `{{end}} 19 ) 20 21 {{if .TableName -}}var TableName{{.ModelStructName}} string{{- end}} 22 23 func init() { 24 {{- if contains .TableName "." }} 25 TableName{{.ModelStructName}} = "{{.TableName}}" 26 {{- else }} 27 if stringutils.IsNotEmpty(config.G_Config.Db.Name) { 28 TableName{{.ModelStructName}} = fmt.Sprintf("%s.{{.TableName}}", config.G_Config.Db.Name) 29 } else { 30 TableName{{.ModelStructName}} = "{{.TableName}}" 31 } 32 {{- end }} 33 } 34 35 // {{.ModelStructName}} {{.StructComment}} 36 type {{.ModelStructName}} struct { 37 {{range .Fields}} 38 {{if .MultilineComment -}} 39 /* 40 {{.ColumnComment}} 41 */ 42 {{end -}} 43 {{.Name}} {{.Type | convert}} ` + "`{{.Tags}}` " + 44 "{{if not .MultilineComment}}{{if .ColumnComment}}// {{.ColumnComment}}{{end}}{{end}}" + 45 `{{end}} 46 } 47 48 ` 49 50 // ModelMethod model struct DIY method 51 const ModelMethod = ` 52 53 {{if .Doc -}}// {{.DocComment -}}{{end}} 54 func ({{.GetBaseStructTmpl}}){{.MethodName}}({{.GetParamInTmpl}})({{.GetResultParamInTmpl}}){{.Body}} 55 `