Internal packages
Context
Section titled “Context”An internal/ directory is a special convention. Code inside internal/ can only be imported by other code inside the same module (or its parent directories). This enforces encapsulation and prevents external usage of internal implementation details.
Example
Section titled “Example”Project structure with an internal package.
Code example
Section titled “Code example”myproject/├── go.mod├── internal/│ └── helper/│ └── helper.go // package helper└── cmd/ └── myapp/ └── main.go // can import internal/helper// internal/helper/helper.gopackage helper
func Help() string { return "internal help"}// cmd/myapp/main.gopackage main
import ( "fmt" "myproject/internal/helper")
func main() { fmt.Println(helper.Help())}Output
Section titled “Output”internal help