From 8f873848b452b65152a4683f1d52d22c1c752944 Mon Sep 17 00:00:00 2001 From: xxjwxc Date: Sat, 12 Dec 2020 18:57:20 +0800 Subject: [PATCH] fix go model gen column name --- data/view/genstruct/common.go | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/data/view/genstruct/common.go b/data/view/genstruct/common.go index a6986cd..4232efe 100644 --- a/data/view/genstruct/common.go +++ b/data/view/genstruct/common.go @@ -164,12 +164,25 @@ func (s *GenStruct) GenerateColumnName() []string { } data.StructName = s.Name for _, v := range s.Em { - data.Em = append(data.Em, struct { - ColumnName string - StructName string - }{ColumnName: v.ColumnName, - StructName: v.Name, - }) + if strings.EqualFold(v.Type, "gorm.Model") { // gorm model + data.Em = append(data.Em, []struct { + ColumnName string + StructName string + }{ + {ColumnName: "id", StructName: "ID"}, + {ColumnName: "created_at", StructName: "CreatedAt"}, + {ColumnName: "updated_at", StructName: "UpdatedAt"}, + {ColumnName: "deleted_at", StructName: "DeletedAt"}, + }...) + } else { + data.Em = append(data.Em, struct { + ColumnName string + StructName string + }{ColumnName: v.ColumnName, + StructName: v.Name, + }) + } + } var buf bytes.Buffer