The ‘fat service’ pattern for Go web applications
alexedwards.net
alexedwards.net
Works well and is very easy to grasp for newcomers to the project.
One pitfall to avoid is mixing request processing with business logic. Certain types of request processing/filtering belong to middlewares and/or the request handlers (Controller Actions). It is very easy to the inexperienced developer to put request processing inside service code.
For example: file upload handling for the user avatar, should it belong to the user service or controller? Or perhaps a dedicated async file upload handler?
I tend to encapsulate messy file upload handling and calling it from the controller so services get a clean file_id. There are different approaches though.
For the database abstraction, you can use sqlc.dev
Next version will have beta support for sqlite but I've been building it from HEAD and have found no issues so far.
Like a 2-layer model.
Once your domain objects get sufficiently complex more than just User, you end up with models. 3-layer i.e MVC
Same goes for java app containers.
Does implementing a different pattern that abstracts away the database engine substantially lower the amount of work it takes to migrate the db in the codebase, and is it worth 5-10 years of dealing with another layer of abstraction that is unused most of the time.
My hypothesis is that even with a more configurable pattern for the DB there is still a lot of code that needs to be changed.
This is ancient stuff, beginner stuff. Also I don't agree that the service should be internal. Useless