How to disable "use of internal package not allowed"

32,111

An import of a path containing the element “internal” 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

Share:
32,111

Related videos on Youtube

Javier Zunzunegui
Author by

Javier Zunzunegui

Updated on July 09, 2022

Comments

  • Javier Zunzunegui
    Javier Zunzunegui 11 months

    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?

    • Volker
      Volker over 6 years
      No there is not. You'll either have to invoke the compiler "by hand" (go tool compile) ore move these packages.
    • Kaedys
      Kaedys over 6 years
      Generally, if they are in an /internal/ subdirectory, that means you're either using a library from before vendoring was added (Go 1.5/1.6), or you're not supposed to use those packages.
    • I159
      I159 over 6 years
      Possible duplicate of Internal packages in Go

Related