func (this *Mysql) Result(sql string) ([]map[string]interface{}, error) {
rows, err := this.link.Query(sql)
errorHandler(err)
res_fileds, _ := rows.Columns()
cache := make([]interface{}, len(res_fileds))
for index, _ := range cache {
var a interface{}
cache[index] = &a
}
var list []map[string]interface{}
for rows.Next() {
_ = rows.Scan(cache...)
item := make(map[string]interface{})
for i, data := range cache {
item[res_fileds[i]] = *data.(*interface{})
}
list = append(list, item)
}
_ = rows.Close()
return list, nil
}
以上代码从网上找的,其中:item[res_fileds[i]] = *data.(*interface{}) 这句是什么意思,我知道是取出数据,但这个语法不懂
有疑问加站长微信联系(非本文作者)