3

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?

1 Answer 1

7
t := time.Now()
contact.Deleted_At = &t

And BTW, you should not use _ in variable names. DeletedAt would be the recommended name.

Sign up to request clarification or add additional context in comments.

2 Comments

uhhhh thank you @Flimzy I was also trying &time.Now() but now I see my error
you must use a var to get address memory of time.Now

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.