к сожалению, так нельзя сделать, так как ваш новый тип не содержит данного метода. Но есть разные решения,
композиция - мы сами определим какие методы нам нужны
type CustomTime time.Time
func (t CustomTime) Format(layout string) string {
return time.Time(t).Format(layout)
}
func NewCustomTime(t time.Time) CustomTime {
return CustomTime(t)
}
либо использовать встраивание ("наследование")
type CustomTime struct {
time.Time
}
var t CustomTime
t.Format("")
поиграете с полным примером
package main
import "fmt"
type A struct {
s string
}
func (a A) MethodOnA() string {
return a.s + " from A"
}
type B struct {
s string
A
}
type C struct {
s string
a A
}
func main() {
a := A{s: "whatever A"}
b := B{s: "whatever B", A: a}
c := C{s: "whatever C", a: a}
fmt.Println("B", b.MethodOnA()) // but also b.A.MethodOnA()
fmt.Println("C", c.a.MethodOnA()) // c.MethodOnA() will not compile
}