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)
}
}
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"
Since the field is of type *string
you have to assign a pointer to a string. That cannot be done on a single line:
s := "No 3A4"
order.Status = &s
Alternatively change the value that order.Status is pointing to:
order.Status = new(string)
*order.Status = "No 3A4"