Golang: Internal Folder

There is a special folder in Golang file structure.

If you create packages inside folder called internal, then the packages cannot be exported/used outside the module.

<root module>/internal/hello/hello.go

<root module>/xxx/internal/hello/hello.go

If you are trying to import the package inside the internal folder then you will get an error:

use of internal package <root-module>/internal/hello not allowed

use of internal package <root-module>/xxx/internal/hello not allowed

For same module use, the package is imported with:

import "module-name/internal/hello"
import "module-name/xxx/internal/hello"

Comments

Leave a Reply

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