将指针赋给Golang中的变量
我在Golang工作,我有一个包含一些字段的结构,其中一个是将指针赋给Golang中的变量,go,Go,我在Golang工作,我有一个包含一些字段的结构,其中一个是time.time字段,用于将Delete\u保存在中,因此可以为空,基本上我将其定义为: type Contact struct { Delete_At *time.Time } 因此,指针可以为null。然后,我有一个方法,当这个值被赋值时,我有如下的东西: contact := Contact{} contact.Deleted_At = time.Now() 但有了它,我得到了: cannot use time.
time.time
字段,用于将Delete\u保存在
中,因此可以为空,基本上我将其定义为:
type Contact struct {
Delete_At *time.Time
}
因此,指针可以为null。然后,我有一个方法,当这个值被赋值时,我有如下的东西:
contact := Contact{}
contact.Deleted_At = time.Now()
但有了它,我得到了:
cannot use time.Now() (type time.Time) as type *time.Time in assignment
我完全理解这是一个糟糕的任务,但是,我该怎么做呢?如何进行转换
t := time.Now()
contact.Deleted_At = &t
顺便说一句,您不应该在变量名中使用
。
DeletedAt
将是推荐的名称。uhhh谢谢@Flimzy我也在尝试&time.Now()
但是现在我看到了我的错误您必须使用var来获取时间的地址内存。现在