1 回答
TA贡献1828条经验 获得超6个赞
但是当我执行程序时,我只从 mysql 表中获取一行而不是所有行
因为您的函数仅返回单个Lwratecardefinition结构,您在循环的每次迭代中覆盖其值。您想返回它们的一部分,例如:
func getRatecard() []Lwratecardefinition {
...
var result []Lwratecardefinition
for results.Next() {
err = results.Scan(&ratecardid,&ratecardgroupid,&serviceid,&usagetypeid,¤cycode,&ledgerid,&pulse,&specialpulse,&normalrate,&offpeakset,&offpeakrate,&peakrate,&ondemandset,&ondemandrate)
result = append(result, Lwratecardefinition{Ratecardid: ratecardid, Ratecardgroupid: ratecardgroupid, Serviceid: serviceid, Usagetypeid: usagetypeid, Currencycode: currencycode, Ledgerid: ledgerid, Pulse: pulse, Specialpulse: specialpulse, Normalrate: normalrate, Offpeakset: offpeakset, Offpeakrate: offpeakrate, Peakrate: peakrate, Ondemandset: ondemandset, Ondemandrate: ondemandrate})
}
if (results.Err() != nil) {
// something went wrong while reading records
...
}
return result
}
- 1 回答
- 0 关注
- 1402 浏览
添加回答
举报