feat: Introduce domain package#21
Conversation
|
I think this structure is better in terms of the DDD. |
|
I'd love to see discussion on this from Go architects more experienced than myself. |
| result := make([]domain.Article, 0) | ||
| for rows.Next() { | ||
| t := new(models.Article) | ||
| t := domain.Article{} |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| } | ||
|
|
||
| func (m *mysqlArticleRepository) Fetch(ctx context.Context, cursor string, num int64) ([]*models.Article, string, error) { | ||
| func (m *mysqlArticleRepository) Fetch(ctx context.Context, cursor string, num int64) ([]domain.Article, string, error) { |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
|
|
||
| } | ||
| func (m *mysqlArticleRepository) GetByID(ctx context.Context, id int64) (*models.Article, error) { | ||
| func (m *mysqlArticleRepository) GetByID(ctx context.Context, id int64) (res domain.Article, err error) { |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| } | ||
|
|
||
| return a, nil | ||
| return |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| return res, domain.ErrNotFound | ||
| } | ||
| return a, nil | ||
| return |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
@jojoarianto actually @bxcodec using named return, so at the end of function, you need to put return
and for pointer afaik is not good using to many pointer, because you will using heap memory instead of stack and will allocated more
| Name: "Iman Tumorang", | ||
| } | ||
| mockAuthorrepo := new(_authorMock.Repository) | ||
| mockAuthorrepo := new(mocks.AuthorRepository) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| func TestDelete(t *testing.T) { | ||
| mockArticleRepo := new(mocks.Repository) | ||
| mockArticle := models.Article{ | ||
| mockArticleRepo := new(mocks.ArticleRepository) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| @@ -0,0 +1,36 @@ | |||
| package domain | |||
There was a problem hiding this comment.
Could you please NOT message in my comments and message directly to the author
There was a problem hiding this comment.
Comments here make good read for new people like us, to understand why this way and not the other way. also pull requests are for code review and comments right?
There was a problem hiding this comment.
I agree with that, but thats not my point.
If you scroll down to the end of this page, there is a comment box, what he has done is replied to my comment similar to what you are doing
There was a problem hiding this comment.
Ohh I see, missed that in a long page scroll. Very sorry
|
Hi @jojoarianto, In this PR there are many changes related to pointer just for safer in memory allocation. So to summarize, I think, if we really don't need a pointer, we better to avoid it. |
|
hey ! Curious to know if you did continue with this domain approach or if you revert back to using the previous one (models at the root) with use cases in each sub-packages. |
|
Hi @AlexGrs , for microservice I use this. But for the monolith, I use the previous one, because Monolith will look messier if we organized like this. |
Hello, everyone who reads this and (maybe who also used my proposed architecture in Go).
Thank you very much for the feedback that I received so far. Just to be honest, I'm very new here in the architecting software worlds. So, I'd rather call it folder structure rather than architecture. As we know, software architecture is not just a single application, but a whole business that architected into one or many applications.
Actually, for the current version in the master branch (when I made this PR), nothing wrongs. By far, this project structure solved many cases of my projects.
But, in this recent months, I try several improvements (also with looking at other people's architecture in Go), so now I decide to introduce a domain package.
In my current structure, we will find something like this:
So there are will be many packaged module like
author,articlethat contains the implementation and also the contractArticleUsecase,ArticleRepository,AuthorRepositorySo, just out of curiosity, I tried a new improvement that proposed by Ben Johnson here: https://medium.com/@benbjohnson/standard-package-layout-7cdbc8391fc1
the
domainpackage. But instead of to move it into the root project, I'd rather move it into a single domain, just for the sake consistency with my previous layout that using packagemodelsSo in my previous layout, I used
modelsand now I renamed it todomainthen move all the interface contract (Usecase and Repository) into this domain package.So it will be more like this:
I don't know yet, is this new layout better than the current layout I used. But, I'll try to use this new layout for my projects. If anything happens, then, this PR will be closed. But if it's good and more comfortable for the developer to use it, then I'll merge this to the branch master. :D
Anyway, if you're a Golang Engineer too, I'd like to hear your opinion about this new proposed layout :D