Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

consumer/handler: Migrate Handler and HandlerFunc from kafka-go #11

Merged
merged 6 commits into from
Oct 10, 2018

Conversation

tealeg
Copy link
Contributor

@tealeg tealeg commented Oct 10, 2018

This PR fixes #8

  • Migrate Handler interface from kafka-go
  • Migrate HandlerFunc from kafka-go
  • Factor away funcHandler struct - we can just hang the HandleMessage function off of a defined type for the method signature instead (I call this HandleMessageFn)
  • 100% test coverage 💯

@tealeg tealeg requested review from asdine and yaziine October 10, 2018 13:52
@tealeg tealeg added this to the feature-parity milestone Oct 10, 2018
@tealeg tealeg self-assigned this Oct 10, 2018

// HandlerFunc wraps a HandleMessagFn in such a way that it complies
// with the Handler interface.
func HandlerFunc(fn HandleMessageFn) Handler {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🌷 You don't need that function actually, a cast does the same thing. You can rename HandleMessageFn to HandlerFunc and let the user cast his func to a HandlerFunc (cf https://golang.org/src/net/http/server.go?s=59707:59754#L1950)

Copy link
Contributor Author

@tealeg tealeg Oct 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! Nice. 🎉


// HandleMessageFn can be used as a Handler
func TestHandleMessageFn(t *testing.T) {
calls := make([]bool, 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📖 Just in case, var calls []bool works (almost) the same way, append accepts a zero value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah.. now that I didn't know. Thanks.

@tealeg tealeg merged commit ec3e9a9 into master Oct 10, 2018
@tealeg tealeg deleted the migrate-consumer-handler branch October 10, 2018 22:25
tealeg added a commit that referenced this pull request Nov 13, 2018
consumer/handler: Migrate Handler and HandlerFunc from kafka-go
tealeg added a commit that referenced this pull request Nov 13, 2018
consumer/handler: Migrate Handler and HandlerFunc from kafka-go
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

consumer: Import consumer/handler code from kafka-go.
3 participants