Skip to content

Commit b812a4d

Browse files
committed
refactor util.go
1 parent c9c7ac8 commit b812a4d

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

util.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,16 @@ func CreateSchema(modelType reflect.Type) *Schema {
3838
return s
3939
}
4040
func MakeSchema(modelType reflect.Type) ([]string, []string, map[string]FieldDB) {
41-
numField := 0
42-
if modelType.Kind() == reflect.Ptr {
43-
numField = modelType.Elem().NumField()
44-
} else {
45-
numField = modelType.NumField()
41+
m := modelType
42+
if m.Kind() == reflect.Ptr {
43+
m = m.Elem()
4644
}
45+
numField := m.NumField()
4746
columns := make([]string, 0)
4847
keys := make([]string, 0)
4948
schema := make(map[string]FieldDB, 0)
5049
for idx := 0; idx < numField; idx++ {
51-
var field reflect.StructField
52-
if modelType.Kind() == reflect.Ptr {
53-
field = modelType.Elem().Field(idx)
54-
} else {
55-
field = modelType.Field(idx)
56-
}
50+
field := m.Field(idx)
5751
tag, _ := field.Tag.Lookup("gorm")
5852
if !strings.Contains(tag, IgnoreReadWrite) {
5953
update := !strings.Contains(tag, "update:false")

0 commit comments

Comments
 (0)