[英]Assigning values to pointer types in a go struct
In an attempt to handle null values when trying to input a struct of data to a database row (using goqu) I've defined a struct similar to为了在尝试将数据结构输入到数据库行(使用goqu)时处理空值,我定义了一个类似于
type datain struct {
id *float32 `db:"id"`
tempr *float32 `db:"temperature"`
}
When you defined a datain<\/code> variable without any initialization, the value of the
id<\/code> was nil, which means you couldn't de-reference it.
当您在没有任何初始化的情况下定义
datain<\/code>变量时,
id<\/code>的值为 nil,这意味着您无法取消引用它。
var datastruct datain
id := stringToFloat32("1234.4")
datastruct.id = &id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.