2
我不知道以下編譯錯誤的原因是什麼。我會感謝任何幫助。即使它具有相同的功能,Golang結構也不會實現接口
./router.go:190: cannot use listener (type webhooklistener.MyListener) as type webhook.Listener in field value:
webhooklistener.MyListener does not implement webhook.Listener (missing webhook.handle method)
have webhooklistener.handle()
want webhook.handle()
客戶:
package webhook
type Listener interface {
handle()
}
type Client struct {
Listener Listener
}
監聽器:
package webhooklistener
type MyListener struct {
}
func (ll MyListener) handle() {
}
路由器:
listener := webhooklistener.MyListener{}
client := webhook.Client{listener} // COMPILATION ERROR
嘗試大寫'handle()'方法,它可能不會被導出以供外部使用。 – tlehman