'Regarding "cannot use time.Now() (type time.Time) as type "
Get "cannot use time.Now() (type time.Time) as type typetime in field value" with below type definition
import ("time")
type typetime time.Time
type Friends struct {
Name string
Birthday typetime
}
John := Friends{Name:"John", Birthday:time.Now()}
If I replace typetime with direct type form (time.Time), there is no problem. what is GO's rule behind?? :>
Solution 1:[1]
time.Time and typetime are different types (though they have the same underlying representations) so you need to convert the type.
John := Friends{Name: "John", Birthday: typetime(time.Now())}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | matt.s |
