I am new to Go having come from a C# background and I am just plain confused about how to structure a Go application.
Say I am building a REST API that will sit on top o
I had .NET MVC experience prior to developing my own application in Go. I did miss that the mapper between BLL and DTO in .NET, but as I write more code in Go, I am getting used to the fact that there is not much free lunch in Go.
The fact that there is almost no framework, NHibernate, Entity, and automatic mapping between URI and views in Go indicates that you probably have to do a lot of work that is taken care of by other frameworks. While this may be inefficient in some people's opinion, it is certainly a great opportunity for learning as well as building a highly customizable application in a less-inefficient manner. Sure, you have to write your own SQL to perform CRUD actions, read the rows returned by the query, map sql.Rows to model, apply some business logic, save changes, map models to DTOs, and send a response back to the client.
As for the difference between DTO and model: DTO is a representation of model for view and has no behaviors (methods). Model is the abstraction of your business logic and has a lot of complex behaviours. I would never implement methods like "checkProvisioning()" or "applyCouponCode()" on a DTO object because they are business logic.
As for mapping database with your model, I won't take any shortcuts because most of the ORM available at this point is pretty primitive. I won't even try to use foreign keys if I have to build my database with ORM. It is better to build your database from a SQL script since you can also configure indexes, triggers, and other bells and whistles. Yes, if the schema changes, you will have to update quite a bit of code to reflect that change, but most of the time it only affects data access layer code.
I have a project that utilizes C#'s MVC design but is completely written in Go, and I bet it's more complex than any toy projects that you can find from published books. If reading the code help you understand the structure better, then go for it: https://github.com/yubing24/das