Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for project structure #10

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

recep
Copy link
Member

@recep recep commented Sep 23, 2021

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 package consumer/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()

@xis
Copy link
Contributor

xis commented Sep 24, 2021

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.

@recep
Copy link
Member Author

recep commented Sep 24, 2021

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.

@yakuter
Copy link
Contributor

yakuter commented Sep 24, 2021

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
...

@xis
Copy link
Contributor

xis commented Sep 24, 2021

Hi again, looks like package.New() structure used in many Go packages then it is ok to use it in this package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants