Skip to content

Commit

Permalink
fix ptr not clean issue
Browse files Browse the repository at this point in the history
  • Loading branch information
陈遇文 committed Feb 14, 2023
1 parent 4fce45e commit f31f14c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions read.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ func (e *headerInfo) getHeaderFieldName(columnIndex int) (header string) {
}

func (e *headerInfo) dataMapping(ptr any, columns []string) (err error) {
ptr = reflect.New(reflect.TypeOf(ptr).Elem()).Interface()

for index, col := range columns {
fieldName := e.getHeaderFieldName(index)
if fieldName == "" {
Expand Down Expand Up @@ -313,5 +311,16 @@ func importData(data any, fn ImportFunc) (errInfo []string) {
return
}

cleanData(data)

return
}

func cleanData(ptr any) {
ptrElemValue := reflect.ValueOf(ptr).Elem()
num := ptrElemValue.NumField()

for i := 0; i < num; i++ {
ptrElemValue.Field(i).Set(reflect.New(ptrElemValue.Field(i).Type()).Elem())
}
}

0 comments on commit f31f14c

Please sign in to comment.