4

I don't know what is the reason of following compilation error. I will appreciate any help.

./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()

Client:

package webhook

type Listener interface {
    handle()
}

type Client struct {
    Listener Listener
}

Listener:

package webhooklistener

type MyListener struct {
}

func (ll MyListener) handle() {

}

Router:

listener := webhooklistener.MyListener{}
client := webhook.Client{listener} // COMPILATION ERROR
1
  • 5
    Try capitalizing the handle() method, it's probably not being exported for external use. Commented Jan 21, 2016 at 16:27

1 Answer 1

16

webhook.Listener's only method is unexported, so only identifiers in that package can implement it. If you want types in other packages to be able to implement it, you need to make it exported:

type Listener interface {
    Handle()
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.