我不完全确定如何问这个问题 - 我有一个使用标准 golang type 关键字从另一个“派生”的类型:
type EWKBGeomPoint geom.Point
我想基本上“覆盖” geom.Point Scan() 和 Value() 函数,所以我有以下函数:
func (g *EWKBGeomPoint) Scan(input interface{}) error {
gt, err := ewkbhex.Decode(string(input.([]byte)))
if err != nil {
return err
}
g = gt.(*geom.Point) // error here
return nil
}
但是,当我运行它时,它有一个接口转换错误:
interface conversion: geom.T is *geom.Point, not *models.EWKBGeomPoint
我不明白为什么会这样——我现在已经看到了多个允许这种行为的代码示例。在我看来,直觉上它应该可以工作,因为它们基本上是相同的类型,具有所有相同的基础变量和函数。
如何将此类型转换为目标类型?
眼眸繁星
幕布斯7119047
Qyouu
随时随地看视频慕课网APP
相关分类