I am working in Golang, I have a Struct that contains some fields, one of them is a time.Time field to save the Delete_Atso it can be null, basically I have defined it as:
type Contact struct {
Delete_At *time.Time
}
So, with the pointer it can be null. Then, I have a method when this value is assigned, I have something like:
contact := Contact{}
contact.Deleted_At = time.Now()
But with it, I get:
cannot use time.Now() (type time.Time) as type *time.Time in assignment
I totally understand that is a bad assignment, but, how should I do it? how the conversion should be done?
t := time.Now()
contact.Deleted_At = &t
And BTW, you should not use _ in variable names. DeletedAt would be the recommended name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With