Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Go扫描仪仍然返回<;零>;_Go_Gorp - Fatal编程技术网

Go扫描仪仍然返回<;零>;

Go扫描仪仍然返回<;零>;,go,gorp,Go,Gorp,首先:我在golang完全是新手,所以我可能不太了解。 我的任务是使用“gorp”从一个数据库编写Go数据提取器。问题在于有一个表具有自定义字段“TimeRange”。 其定义如下: type TimeRange struct { From string To string } 不幸的是,当我试图获取行时,我得到了扫描仪错误,所以我意识到我需要一个自定义扫描仪 // Scan - Implement the database/sql scanner interface fun

首先:我在golang完全是新手,所以我可能不太了解。 我的任务是使用“gorp”从一个数据库编写Go数据提取器。问题在于有一个表具有自定义字段“TimeRange”。 其定义如下:

type TimeRange struct {
    From string
    To  string
}
不幸的是,当我试图获取行时,我得到了扫描仪错误,所以我意识到我需要一个自定义扫描仪

// Scan - Implement the database/sql scanner interface
func (tr *TimeRange) Scan(value interface{}) error {
    tr.From = "mis"
    tr.To = "lala"
    fmt.Printf("%v\n", *tr)

    return nil
}
所以我希望在返回的字符串中看到固定的“{mis lala}”。 为什么我会得到:

var q2 []models.Dashboard
result, err := dbmap.Select(&q2, "select * from dashboard where id=3")
fmt.Printf("q2=%v\n", q2)
印刷品:

p2=[{{<nil> Tomek b1f6f0ba-f618-00d6-6d24-8410a9219c95}}]
p2=[{{Tomek b1f6f0ba-f618-00d6-6d24-8410a9219c95}]
即: 时间范围、用户名和UUID


可能很重要:使用“gorp”进行数据库管理

将在传递值类型时调用scan函数到
dbmap.Select()
,因此在您的情况下,您需要将
仪表板
实现为
扫描仪