Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将指针赋给Golang中的变量_Go - Fatal编程技术网

将指针赋给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.

我在Golang工作,我有一个包含一些字段的结构,其中一个是
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来获取时间的地址内存。现在