One minute
Avoid Golang Git Conflicts in Structs
The usage of structs is key in every Golang project. If we are a team of several developers that work in the same repository we might face a lot of git conflicts. This is due to the code style that Golang uses where all the types of a struct need to be aligned.
Here is an example of a dependency container struct:
type Services struct {
CommandBus command.Bus
QueryBus query.Bus
Logger logger.Logger
...
}
When a developer adds a new field it might trigger a reformat that would affect all the lines of the struct so that developer would commit a change affecting many lines.
To avoid that in our team in Wallbox we started grouping the structs by type to minimize this situation.
For example we might have something like:
type Services struct {
CommandBus command.Bus
QueryBus query.Bus
Logger logger.Logger
}
Of course having big struct could be considered a bad smell so try to keep them as small as possible.
For example we have a services struct by each module of the application so each one is more focused and small.