How do I split internal vs public packages in Go projects?

In Go projects, it's important to organize your code into internal and public packages to maintain encapsulation and promote code reuse. Internal packages are only accessible within a specific module, while public packages can be imported and used by other modules. This structure helps in managing dependencies effectively and ensures that your project's architecture is clear.

To split internal and public packages, you would typically create a directory called internal for your internal packages and organize your public packages in the root or other designated directories.

myproject/ ├── internal/ │ └── myinternalpkg/ │ └── myinternal.go ├── publicpkg/ │ └── mypublic.go └── main.go

Go Go packages internal packages public packages Go project structure Go modules