interface conversion: interface {} is int64, not []uint8

fancyecommerce · · 2846 次点击 · 开始浏览    置顶
这是一个创建于 的主题,其中的信息可能已经有所发展或是发生改变。

查询语句: ``` rows, err := mysqlDB.Query("SELECT * FROM `article` where `id` = ? ", 32); ``` 相应函数为: ``` // Query via pool func (p *SQLConnPool) Query(queryStr string, args ...interface{}) ([]map[string]interface{}, error) { rows, err := p.SQLDB.Query(queryStr, args...) if err != nil { log.Println(err) return []map[string]interface{}{}, err } defer rows.Close() columns, _ := rows.Columns() scanArgs := make([]interface{}, len(columns)) values := make([]interface{}, len(columns)) for i := range values { scanArgs[i] = &values[i] } rowsMap := make([]map[string]interface{}, 0, 10) for rows.Next() { //将行数据保存到record字典 err = rows.Scan(scanArgs...) rowMap := make(map[string]interface{}) for i, col := range values { if col != nil { rowMap[columns[i]] = string(col.([]byte)) } } rowsMap = append(rowsMap, rowMap) } if err = rows.Err(); err != nil { return []map[string]interface{}{}, err } return rowsMap, nil } ``` 报错信息: ``` interface conversion: interface {} is int64, not []uint8 /usr/local/go/src/runtime/panic.go:491 (0x42b512) gopanic: reflectcall(nil, unsafe.Pointer(d.fn), deferArgs(d), uint32(d.siz), uint32(d.siz)) /usr/local/go/src/runtime/iface.go:172 (0x40f9b6) panicdottypeE: panic(&TypeAssertionError{iface.string(), haveString, want.string(), ""}) /root/go/src/github.com/fecshopsoft/golang-db/mysql/mysql.go:74 (0x92cda2) (*SQLConnPool).Query: rowMap[columns[i]] = string(col.([]byte)) /root/go/src/github.com/fecshop/go_fec_api/handler/article.go:54 (0x92e475) ArticleData.OneByUrlKey: _, _ = mysqlDB.Query("SELECT * FROM `article` where `id` = ? ", 32); /root/go/src/github.com/fecshop/go_fec_api/router/router.go:42 (0x92fba3) Begin.func2: handler.Article.OneByUrlKey(c, mysqlDB) /root/go/src/github.com/gin-gonic/gin/context.go:107 (0x8e2812) (*Context).Next: c.handlers[c.index](c) /root/go/src/github.com/gin-gonic/gin/recovery.go:46 (0x8f4ab9) RecoveryWithWriter.func1: c.Next() /root/go/src/github.com/gin-gonic/gin/context.go:107 (0x8e2812) (*Context).Next: c.handlers[c.index](c) /root/go/src/github.com/gin-gonic/gin/logger.go:83 (0x8f3deb) LoggerWithWriter.func1: c.Next() /root/go/src/github.com/gin-gonic/gin/context.go:107 (0x8e2812) (*Context).Next: c.handlers[c.index](c) /root/go/src/github.com/gin-gonic/gin/gin.go:359 (0x8eb925) (*Engine).handleHTTPRequest: c.Next() /root/go/src/github.com/gin-gonic/gin/gin.go:326 (0x8eb0ba) (*Engine).ServeHTTP: engine.handleHTTPRequest(c) /usr/local/go/src/net/http/server.go:2619 (0x664903) serverHandler.ServeHTTP: handler.ServeHTTP(rw, req) /usr/local/go/src/net/http/server.go:1801 (0x660a4c) (*conn).serve: serverHandler{c.server}.ServeHTTP(w, w.req) /usr/local/go/src/runtime/asm_amd64.s:2337 (0x459790) goexit: BYTE $0x90 // NOP ``` 看报错信息明白个大概,但是不知道如何改,来消除报错。

有疑问加站长微信联系(非本文作者)

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

2846 次点击  
加入收藏 微博
11 回复  |  直到 2018-01-29 17:09:36
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传