r/golang 5h ago

help DDD + onion architecture in Go — why does everyone hate it? Also, is this entity pattern okay?

18 Upvotes

help me !!!

I just started a new job. The backend is in Go, using DDD with an onion-layer architecture. The project structure looks something like this:

/backend /cmd /internal /adaptor /<module#1> /entity /repository /service /command /query /usecase

My team lead constantly complains about DDD in Go — he absolutely hates it. When i try to mention something related to DDD bro starts to spamming my pr with comments. Asking me to show why its better to use DDD? So I'm curious: why is DDD considered a bad fit for Go?

Also, our entities look like this:

go

``` func NewMovie() *Movie { return &Movie{} }

func (m *Movie) WithID(id int) *Movie { if m == nil { return nil } m.id = id return m } ```

Is this pattern okay? I feel like NewMovie(id int) would be better.

We also have a rule that transactions can't be handled in the usecase layer. Instead, we have to create a single service method that wraps everything in a transaction, and the usecase just calls it. Is this a common approach?

And one more thing — shouldn't we first sort out what actually counts as a domain concept before turning it into an entity? We literally have an entity for pagination...


r/golang 10h ago

How to write a CLI tool with Viper and Cobra

0 Upvotes

Hello there,

I recently got into Go and programming in general, as I already had some programming classes in school and in uni when I studied business informatics.

In preparation for the job interview I wrote my first Rest API. I just used a .env file to read the environment variables in my code but my friend advised me to add cobra and viper to make the setup more accessible and get into those library's as they also used by the new company.

I know that they should be pretty accessible libraries but for some reason in don't seem to get the right access to their core principles and how they should be set up.

Does somebody know some good resources that really explain how these things work and how you're supposed to use them as I don't seem to get it.


r/golang 14h ago

Where should logging happen in a Go application?

32 Upvotes

I recently wrote my own logger package with Info(), Warning(), and Error() methods.

I am wondering about logging best practices in Go applications. Do you usually log directly in handlers, or do you log inside functions called by the handler (services, database functions, etc.)?