dongyuqi3808 2017-06-19 19:39
浏览 305
已采纳

插入自定义时间,实现了Scanner和Valuer,但仍然出错

I have a custom time format that is the result of some custom unmarshalling:

type customTime struct {
    time.Time
}

I have implemented the Scanner and Valuer interface on this customTime like so:

func (ct *customTime) Scan(value interface{}) error {
    ct.Time = value.(time.Time)
    return nil
}

func (ct *customTime) Value() (driver.Value, error) {
    return ct.Time, nil
}

But it still errs when I try to do the insert:

sql: converting Exec argument $3 type: unsupported type main.customTime, a struct

What am I missing?

  • 写回答

1条回答 默认 最新

  • dousi1961 2017-06-19 19:44
    关注

    Found the solution, Scanner and Valuer should be implemented on the actual value and not a pointer to the customTime

    func (ct customTime) Scan(value interface{}) error {
        ct.Time = value.(time.Time)
        return nil
    }
    
    func (ct customTime) Value() (driver.Value, error) {
        return ct.Time, nil
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度