Module Code Organization
Explore how to organize module code effectively in event-driven Golang applications. Understand the use of internal packages for controlling dependencies, follow the guideline of accepting interfaces and returning structs, and implement interface checks to ensure robust and loosely coupled modules.
We'll cover the following...
Each of the modules that makes up our application exposes a protocol buffer API and a small module file that contains the composition root for the module code. The modules also have their internal packages to keep unintentional imports from being made between the modules.
The above figure illustrates how the multiple internal packages help us manage our relationships and control the dependencies between the modules:
/root/internal: This package can be imported by/rootand any package found in the directory tree under it./root/pkg-b/internal: This package can only be imported by/root/pkg-band any package found in the directory tree under it. Both/rootand/root/pkg-awill not be permitted ...