在本地下载golang源码后编译器提示错误:use of internal package not allowed
![image.png](https://static.studygolang.com/210209/c5776ee080e0024fdcf68a3f480382c7.png)
GOROOT:/usr/local/go
GOPATH:/Users/myhome/work
源码目录:/Users/myhome/go1.16
SDK版本:Go 1.16beta1
环境:Mac mini m1
预期是想在编辑器不报错情况下阅读源码、编译、调试。
请各位大佬指点迷津。感谢!
可以在goland的中GO SDK下把bytealg 复制一份并重命名为bytealg1(复制在bytealg同一路径下),然后import "internal/bytealg1"
#1
更多评论
>Internal packages (packages that are inside a folder that has an internal folder in their path) can only be imported from packages rooted at the parent of the internal folder.
>
>E.g. a package pkg/foo/internal/bar can be imported by the package pkg/foo/internal/baz and also from pkg/foo/baz, but cannot be imported by the package pkg nor can it be imported by pkg/bar. This is by design. This is so big, complex packages can be broken into smaller packages without having to expose internals.
>
>You have to treat internal packages as "private" or non-existent from the "outside".
>
>See related: Can I develop a go package in multiple source directories?
>
>Read more about internal packages at Command go: Internal Directories.
>
>Internal packages are a compiler restriction. If you want to expose them (if you want to use an internal package) in your own project, you have to remove the internal folder, and then of course you have to change the imports (import paths) too.
[use-of-internal-package-not-allowed](https://stackoverflow.com/questions/59342373/use-of-internal-package-not-allowed)
#2