Reputation: 16055
For my current project I am implementing a code (separate package) to be part of binary which (this package) can also be imported by other projects (binaries) as if it was a library. The reason why such package is not a part of shared library is that it's functionality is tied tightly with the mentioned project.
The problem is this package provides an interface with two implementations
My question is: is there a mechanism in Go how to prevent certain part of package or it's sub-package from being imported by another projects?
It's mostly just an aesthetic issue since the DB-accessing implementation won't work at all (throwing errors) when used outside of current project.
Upvotes: 1
Views: 131
Reputation: 109417
Yes, you can use an internal directory.
Code in or below a directory named "internal" is importable only by code in the directory tree rooted at the parent of "internal".
Upvotes: 4