heetch / felice

Felice is a nascent, opinionated Kafka library for Go, in Go
MIT License
20 stars 1 forks source link

Have a constructor for the Consumer type #22

Closed yaziine closed 5 years ago

yaziine commented 5 years ago

I think that we should have a constructor for the Consumer type because its zero value is not usable.

For example, if I create a consumer like that:

c := consumer.Consumer{}

c is not usable because I need to have some fields to be initialized (think of the Logger for example).

Two proposals:

tealeg commented 5 years ago

I don't think it's true that it's not usable - the RetryInterval already defaults, and both Logging and Metrics are optional.

yaziine commented 5 years ago

There are optional indeed but if I want to use the Logger for example before calling the Handle method (which calls the setup one). How can I do?

The use case is for kafka-go, I need the Logger before any calls to Handle.

tealeg commented 5 years ago

So you simply initialise the Consumer with the Logger:

c := &Consumer{Logger: myLogger}

.. no?

yaziine commented 5 years ago

Yes you are right, I am always wondering when should I use a constructor or not.