This question already has an answer here:
According to my requirements, I created one struct as -
type MyRule struct {
CreatedAt time.Time `json:"createdAt" datastore:"createdAt,noindex"`
UpdatedAt *time.Time `json:"updatedAt" datastore:"updatedAt,noindex"`
}
for createdAt field, I am able to store current time as-
MyRule.CreatedAt = time.Now()
However, the same thing does not work to store current time in updatedAt
field of MyRule
struct as it's type is *time.Time
and not time.Time
.
Here, I can't change field type of updatedAt
because *time.Time
allows me to accept nil as updatedAt
value when I create any rule.
If I try to do this as-
MyRule.UpdatedAt = time.Now()
It gives me below error-
cannot use time.Now()(type time.Time) as type *time.Time in assignment
How can I store current time value in updatedAt field of type *time.Time and not time.Time
</div>