duancao2082 2019-09-10 15:30
浏览 79

GoLang解析点数据类型

In my DB i have a table that require a coordinate value. such value is stored as a

Point DataType

however when i try to obtain such value, GO responds with an error:

unsupported Scan, storing driver.Value type []uint8 into type *models.Point

this is my Model

type Business struct {
    ID int `json:"id,omitempty"`
    Name string `json:"name,omitempty"`
    Owner string `json:"owner,omitempty"`
    Coordinates Point `json:"coordinates,omitempty"`
    Reason string `json:"reason,omitempty"`
    BusinessBranches []BusinessBranches `json:"reason,omitempty"`
}

and this is the Point type model

type Point struct {
    X float64 `json:"lat"`
    Y float64 `json:"lon"`
}

in my controller i call the selection of Business.

func (b *BusinessRepoImpl) Select() ([]models.Business, error) {
    business_list := make([]models.Business, 0)
    rows, err := b.Db.Query("SELECT id, name, owner, coordinates, reason FROM business")
    if err != nil {
        return business_list, err
    }
    for rows.Next() {
        business := models.Business{}
        err := rows.Scan(&business.ID, &business.Name, &business.Owner, &business.Coordinates, &business.Reason)
        if err !=  nil {
            fmt.Println(err)
            break
        }
        business_list = append(business_list, business)
    }
    err = rows.Err()
    if err != nil {
        return business_list, err
    }
    return business_list, nil
}

anyone know how to parse such DataType, so i can read it and store it? Thanks. :)

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?
    • ¥15 matlab(相关搜索:紧聚焦)
    • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
    • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
    • ¥50 需求一个up主付费课程
    • ¥20 模型在y分布之外的数据上预测能力不好如何解决