dotn30471 2018-07-31 02:26
浏览 5

在Go Lang中分配给结构的指针的属性

I'm getting the following error
Cannot use '"No 3A4"' (type string) as type *string in assignment

How can I add a default value for the query doesn't return rows so I can't use the row.Scan() function, sample code below.

func (orders *Orders) getOrderStatus() {
    var err error
    for _, order := range *orders {
        row := db.QueryRow("SELECT status FROM mss_orders WHERE externalorderkey = ? ORDER BY tipo ASC LIMIT 1", order.PoNumber)
        err = row.Scan(&order.Status)

        if err != nil {
            &order.Status = "No 3A4"    <----- How can I do this?
        }

        fmt.Printf("%+v
", order)
    }
}
  • 写回答

2条回答 默认 最新

  • dtzk85937 2018-07-31 02:54
    关注

    Based on the error, we know that &order.Status is type *string. Yet you're trying to assign it a value of type string. You could make a pointer to the string instead:

    str := "No 3A4"
    &order.Status = &str
    

    Or you could just assign to order.Status directly:

    order.Status = "No 3A4"
    
    评论

报告相同问题?

悬赏问题

  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教