DEV Community

Discussion on: Clean Architecture using Golang

Collapse
 
ezhydzetski profile image
Euheni Zhydzetski

By this implementation, User struct from entity.go is a domain/business entity. So it should know nothing about json(API), bson(Persistance) or any other infrastructure.
Such Golang tags make the domain entity dependent from infrastructure. And it is an insidious dependency: linter can't easly detect it on syntax layer (no imports) and should understand semantic of tags information.
So, I recommend to avoid any tags in domain layer. Instead use DTOs and mappings in infrastructure:

  • http.UserJSON, or even http.UserViewJSON, http.UserCreateJSON with json tags
  • mongodb.UserDoc with bson tags
  • http.UserJSON -> domain.User <- mongodb.UserDoc

Thanks for the article. Ready for discussion.

Collapse
 
eminetto profile image
Elton Minetto

Yes! Actually, this is a correct behavior and I’m using something like this in my codes. I was thinking in an update to this post, but your comment cover it :) thanks