的方法,我有一個名爲類型,我需要做做一些JSON unmarshmaling:調用命名類型
type StartTime time.Time
func (st *StartTime) UnmarshalJSON(b []byte) error {...}
由於StartTime
是time.Time
,我認爲我將能夠調用屬於方法到time.Time
,如Date()
:
myStartTime.Date() // myStartTime.Date undefined (type my_package.StartTime has no field or method Date)
我如何添加方法,以現有的類型,同時保留其原有的方法呢?
見[此答案](http://stackoverflow.com/questions/29397801/whats-該最佳實踐推斷方法/ 29397985#29397985)的例子關於嵌入/不嵌入自定義時間類型之間的區別。 –