I am having a bit of difficulty in designing my Go code.
I'll try to demonstrate things with a very simple example of adding a new user to the database. I have 3 major components in this example: a handler, a service and a dao layer.
My Handler is only doing one thing: Calling a service.
The service is managing all the business logic and then calling the DAO to interact with the database.
The DAO also has only responsibility: Storing in the database.
Also, just for context I am making GraphQL(gqlgen) requests to interact with my ElasticSearch(olivere/elastic) database, but that shouldn't affect the design too much.
MY CODE:
https://play.golang.org/p/Wm9qubLJIGM
I have read a lot of posts about using structs/interfaces to handle the service layer and DAO layer, but I am unable to implement the same in my usecase.
I don't have a background in Java/C# so I'm not well versed with OOP Principles but I did read a lot on MVC based on other answers.
My code works for now, but is it bad code?
I don't want to be passing parameters from one function to another. Is there a way to that with receivers on methods?
Rough comments:1. I tend to shy away from packages named "utils" since they often attract functions from all over the place of a project. It is often better to keep such functions in the packages where they are used, or name them after what kind of functions they contain.