首页 > 其他 > 详细

【原】GO 语言常见错误

时间:2014-03-11 23:23:42      阅读:557      评论:0      收藏:0      [点我收藏+]

1. Scan error on column index 4: converting string "" to a int: strconv.ParseInt: parsing "": invalid syntax。

 这是由于使用MySQL go 驱动时,对应表字段int 为空时(未填值),Scan(&intVal)时(intVal 为int类型)时会报此错。另go转换index 从0开始。

2. range 使用时,注意使用的是值拷贝。

    pictures := make([]Picture, 8)
    for index,picture := range pictures {
      pictures[index].init(index+1) //此处需要改picture内容时,不能使用picture.init(index+1),因为picture为pictures中的一份值拷贝
   }

【原】GO 语言常见错误,布布扣,bubuko.com

【原】GO 语言常见错误

原文:http://www.cnblogs.com/syru/p/3594987.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!