1 回答
TA贡献1886条经验 获得超2个赞
找到了一个基于Pass string slice to variadic empty interface 参数的答案
以下是完成任务的更新代码
func GetAgregatedDownloadsFromTo(constrains dao.Constrains) [] dao.NameValue {
dbMap := utils.GetDBConnection("radsummary");
defer dbMap.Db.Close()
var totalDailyDownloads[] dao.NameValue
query := "SELECT SUM(outputoctets) as value ,date as name FROM dailyacct where date >= ? AND date < ? "
if len(constrains.LocationGroups) > 0 {
args := make([]interface{}, len(constrains.LocationGroups)+2)
args[0] = constrains.From
args[1] = constrains.To
for index, value := range constrains.LocationGroups { args[index+2] = value }
query = query + " AND calledstationid=? "
for i := 1; i< len(constrains.LocationGroups); i++ {
query = query + " OR calledstationid=? "
}
query = query + " group by date"
print(query)
_, err := dbMap.Select(&totalDailyDownloads, query, args...)
if err != nil {
panic(err.Error()) // proper error handling instead of panic
}
}
return totalDailyDownloads
}
在这里,我不得不将字符串切片转换为接口切片。
- 1 回答
- 0 关注
- 164 浏览
添加回答
举报