go – golang disable "use of internal package not allowed"-ThrowExceptions

Exception or error:

I have a go program that inspects a large repository, selects some packages of interest, and then generates a new main.go file that has:

import(
  _ (package of interest here)
  _ (another package of interest here)
  ...
)
func main() {...}

The main is interested in some values these packages set in their init method.

However some of these packages have (…)/internal/(…) paths and so I get use of internal package not allowed when trying to run the generated main.go.

Is there some compiler / linker / other flag that disables the internal path check?

How to solve:

An import of a path containing the element “internal” is disallowed if the importing code is outside the tree rooted at the parent of the “internal” directory. There is no mechanism for exceptions. In particular, by design, there is no ACL mechanism for allowing a whitelist of other packages to use an internal package.

Proposal for the rule

Leave a Reply

Your email address will not be published. Required fields are marked *