```go
func selectExe(sqlStr string,afterScan func(sct *[]interface{}),sctType interface{},args ...interface{})([]interface{},error){
thisTx := getSqlTx()
defer thisTx.Commit()
stmt, err := thisTx.Prepare(sqlStr)
defer stmt.Close()
if err != nil {
log.Fatal(err)
return nil,err
}
rows, err := stmt.Query(args...)
if err != nil {
log.Fatal(err)
return nil,err
}
result := make([]interface{}, 0)
s := reflect.ValueOf(sctType).Elem()
length := s.NumField()
oneRow := make([]interface{}, length)
for i := 0; i < length; i++ {
oneRow[i] = s.Field(i).Addr().Interface()
}
defer rows.Close()
for rows.Next() {
err := rows.Scan(oneRow...)
afterScan(&oneRow) // 这一行
if err != nil {
panic(err)
}
result = append(result, s.Interface())
}
return result,nil
}
```
在上面的 afterScan 处,回调处理下面代码
```go
func(sct *[]interface{}) {
// 想要在这里把 sct 转为 postStruct 结构体,但是尝试了不行,求助啊!!!
//post := (*sct).(postStruct)
}
```
有疑问加站长微信联系(非本文作者)