gpt4 book ai didi

go - 在 Golang 中填充一个对象

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

如何使用 for 循环填充 todos-Object?

type Row struct {
Name string
Completed bool
Due time.Time
Rcount string
}
type Rows []Row
todos := Rows{
Row{Name: "Write presentation"},
Row{Name: "Host meetup"},
}

最佳答案

这个问题有点难以理解,但请尝试从以下模式开始(为简洁起见省略了错误处理):

rows, _ := db.Query(string, args...)
var Rows []Row
for rows.Next() {
var r Row
rows.Scan(&r.Name, &r.Completed, &r.Due, &r.Rcount)
Rows = append(Rows, r)
}

如果你能澄清问题,也许我们可以提供更好的答案

关于go - 在 Golang 中填充一个对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37723883/

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