【发布时间】:2018-04-19 07:00:02
【问题描述】:
我得到了以下代码:
package catalog
...
type Time time.Time
func (t Time) MarshalJSON() ([]byte, error) {
got := time.Time(t)
stamp := fmt.Sprintf("\"%s\"", got.In(time.UTC).Format("2006-01-02T15:04:05.000Z"))
return []byte(stamp), nil
}
我正在尝试像这样使用它:
package main
func main() {
...
t := *a.StartTime <<== This returns a time.Time
t2 := catalog.Time{t}
}
而且,我收到以下错误:
catalog.Time composite literal uses unkeyed fields
implicit assignment of unexported field 'wall' in catalog.Time literal
cannot use t (type time.Time) as type uint64 in field value
too few values in structure initializer
import (catalog ".../go-catalog-types.git")
我也尝试过:t2 := catalog.Time{Time: t} 和其他几个变体。有什么建议吗?
谢谢
【问题讨论】:
标签: go