gpt4 book ai didi

go - MapScan 无法解码为非指针 int64

转载 作者:数据小太阳 更新时间:2023-10-29 03:22:25 25 4
gpt4 key购买 nike

我使用了 MapScan 并用这个错误对其进行了迭代

can not unmarshal into non-pointer int64

第一次迭代后出错。

这是我正在处理的代码:

type NotFinishedTBLFields struct {
Bulk_id int64
Recipient string
Operator string
Tracking_code string
}

func FetchNotFinishedTBLRows() *NotFinishedTBLFields {

rowValues := make(map[string]interface{})
var row NotFinishedTBLFields

iter := Instance().Query(fmt.Sprintf(`SELECT * FROM %q `, NotFinishedTBLConfig.Name)).Consistency(gocql.All).Iter()

for iter.MapScan(rowValues) {
fmt.Println("rowValues ",rowValues)
row = NotFinishedTBLFields{
Bulk_id: rowValues["bulk_id"].(int64),
Recipient: rowValues["recipient"].(string),
Operator: rowValues["operator"].(string),
Tracking_code: rowValues["tracking_code"].(string),
}

}
if err := iter.Close(); err != nil {
log.Fatal(err)
}
return &row
}

最佳答案

我找到了结果:

rowValues = make(map[string]interface{})

我也必须在 for loop 中添加这一行。

这是最终代码:

func FetchNotFinishedTBLRows(limit int) []NotFinishedTBLFields {

rowValues := make(map[string]interface{})
var row NotFinishedTBLFields
var rows []NotFinishedTBLFields
iter := Instance().Query(fmt.Sprintf(`SELECT * FROM %q Limit %d`, NotFinishedTBLConfig.Name, limit)).Consistency(gocql.All).Iter()

for iter.MapScan(rowValues) {
fmt.Println("rowValues ", rowValues)
row = NotFinishedTBLFields{
Bulk_id: rowValues["bulk_id"].(int64),
Recipient: rowValues["recipient"].(string),
Operator: rowValues["operator"].(string),
Tracking_code: rowValues["tracking_code"].(string),
}
rows = append(rows, row)
rowValues = make(map[string]interface{})
}
if err := iter.Close(); err != nil {
log.Fatal(err)
}
return rows
}

关于go - MapScan 无法解码为非指针 int64,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51464646/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com