kafka-do
kafka-do copied to clipboard
Update for project structure
I made some changes to separate the project structure. #5
-
We can keep constants in constants.go file instead of hardcoded
kgo.GroupProtocol("roundrobin")
--> constants/constants.go -
We can keep commonly used types under model package
type Message []byte
--> model/message.go -
We can make producer and consumer files independent from each other by moving them into separate packages. producer.go, producer_test.go --> producer package
producer/producer.go and producer/producer_test.go
consumer.go, consumer_test.go --> consumer packageconsumer/consumer.go and consumer/consumer_test.go
-
We can change the function names newProducer and newConsumer to New keyword. Because now we have divided the consumer and producer files into different packages. package names Example:
NewConsumer()
-->consumer.New()
NewProducer()
-->producer.New()
Hi @recep and thanks for your work and support.
Moving consumer and producer to seperate packages may be good but code is so small for this structure for me.
I think package.New()
structure looks clean and beautiful but looks like weird in the Go practices. I'll be waiting for the other team members reviews to conclude the pull request.
Hi @xis thanks for the review. There are some points:
- package.New() structure often used in GO, like errors.New() error-package
- I think dividing the code structure into parts can enable us to make new developments independently. It can make tests more understandable.
Hello guys. I just saw the conversation. Using the New function is the better way. Let me show you a standard Go package structure. Of course if you use some kind of singleton pattern, there will be changes however the idiomatic way is almost like this.
package matematik
type Matematik struct {
ilkSayi int
ikinciSayi int
toplam int
}
func New() *Matematik {
return &Matematik{
ilkSayi: 0,
ikinciSayi: 0,
}
}
func (m *Matematik) Topla() {
m.toplam = m.ilkSayi + m.ikinciSayi
}
func (m *Matematik) GetToplam() int {
return m.toplam
}
There are so many examples for this: https://github.com/gin-gonic/gin/blob/master/gin.go https://github.com/sirupsen/logrus/blob/master/logger.go ...
Hi again, looks like package.New()
structure used in many Go packages then it is ok to use it in this package.