Splitting up code into internal packages
To hide some of your internal logic in Go you can use private members. But when you depend on too much internal logic, you face the difficulty of sorting through tons of private methods that don’t really have with one-another to deal with.
What you can do is split up your Go package into multiple packages. Either you:
or you make an internal package, like the
Both options of splitting up the code base is to better conform with the Single Responsibility Principle (SRP), which is one of the key focus points in.
There’s also multiple, which is good to read up on to take full advantage of both your internal packages, as well as any other imported packages.
Including the word
internal in your package chain means it will be treated differently by the Go compiler.
It’s like a gate, where you can only access packages from the direct parents of the internal package or sub-packages of an internal package.
The above package would be accessible by:
But it would not be accessible by:
- Mike Van Sickle. (2019, July 29). Deep Dive into Go Packages [Course]. Pluralsight. https://www.pluralsight.com/courses/go-packages-deep-dive