-
Notifications
You must be signed in to change notification settings - Fork 1
consumer/handler: Migrate Handler and HandlerFunc from kafka-go #11
Conversation
- There's no need for the struct, it just holds a function, that's just as valid a type to hang another function off of.
consumer/handler/func.go
Outdated
|
||
// HandlerFunc wraps a HandleMessagFn in such a way that it complies | ||
// with the Handler interface. | ||
func HandlerFunc(fn HandleMessageFn) Handler { |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! Nice. 🎉
consumer/handler/func_test.go
Outdated
|
||
// HandleMessageFn can be used as a Handler | ||
func TestHandleMessageFn(t *testing.T) { | ||
calls := make([]bool, 0) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
consumer/handler: Migrate Handler and HandlerFunc from kafka-go
consumer/handler: Migrate Handler and HandlerFunc from kafka-go
This PR fixes #8
Handler
interface from kafka-goHandlerFunc
from kafka-gofuncHandler
struct - we can just hang theHandleMessage
function off of a defined type for the method signature instead (I call thisHandleMessageFn
)