【发布时间】:2021-05-07 08:09:02
【问题描述】:
我正在尝试在 Go 中处理一个结构,它有两个属性需要我作为时间戳:
type Asset struct {
Owner string `json:"owner"`
Key string `json:"key"`
StartDate Time `json:"startDate"`
EndDate Time `json:"endDate"`
Type string `json:"type"`
Amount int `json:"amount"`
Facility string `json:"facility"`
State string `json:"state"`
}
我导入了“time”包,但是编译器给了我一个 Time 类型的错误:
“未声明名称:时间编译器未声明名称”
关于为什么会发生这种情况的任何提示?
【问题讨论】:
-
您必须对其进行限定。
time.Time。 golang.org/ref/spec#Qualified_identifiers