-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks much cleaner
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.
article/repository/mysql_article.go
Outdated
@@ -62,14 +61,14 @@ func (m *mysqlArticleRepository) fetch(ctx context.Context, query string, args . | |||
return result, nil | |||
} | |||
|
|||
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.
@@ -82,44 +81,43 @@ func (m *mysqlArticleRepository) Fetch(ctx context.Context, cursor string, num i | |||
return res, nextCursor, err | |||
|
|||
} | |||
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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
ID: 1, | ||
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.
@@ -152,18 +151,18 @@ func TestStore(t *testing.T) { | |||
} | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ask: Why not domains
(plural)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please NOT message in my comments and message directly to the author
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
,article
that contains the implementation and also the contractArticleUsecase
,ArticleRepository
,AuthorRepository
So, just out of curiosity, I tried a new improvement that proposed by Ben Johnson here: https://medium.com/@benbjohnson/standard-package-layout-7cdbc8391fc1
the
domain
package. 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 packagemodels
So in my previous layout, I used
models
and now I renamed it todomain
then 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