How it works...
This recipe shows how to separate basic concerns in an applications. For resources such as models or clients, it's good to first create an interface for what actions it will perform, then satisfy that interface and provide convenient setup functions. Model/client code will also frequently produce custom error types.
Next, we create our controller and handlers, which isolate all client requests to the server. The Controller object uses the storage interface, making it easy to swap storage solutions without modifying application code. Lastly, main.go is used to set up routes, initialize controllers, and configure things such as logging. We use a package-level global logger so that any of our methods can freely log if needed. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access