Updated the README.md file by adding a paragraph that provides further clarification on the purpose of the 'internal' directory.

This commit is contained in:
anazibinurasheed 2023-09-06 13:19:34 +05:30
parent 8ce8aefe00
commit 2d1e32a7e0

View File

@ -68,6 +68,8 @@ Private application and library code. This is the code you don't want others imp
You can optionally add a bit of extra structure to your internal packages to separate your shared and non-shared internal code. It's not required (especially for smaller projects), but it's nice to have visual clues showing the intended package use. Your actual application code can go in the `/internal/app` directory (e.g., `/internal/app/myapp`) and the code shared by those apps in the `/internal/pkg` directory (e.g., `/internal/pkg/myprivlib`).
You use internal directories to make packages private. If you put a package inside an internal directory, then other packages cant import it unless they share a common ancestor. Its the only directory named in Gos documentation and has special compiler treatment.
### `/pkg`
Library code that's ok to use by external applications (e.g., `/pkg/mypubliclib`). Other projects will import these libraries expecting them to work, so think twice before you put something here :-) Note that the `internal` directory is a better way to ensure your private packages are not importable because it's enforced by Go. The `/pkg` directory is still a good way to explicitly communicate that the code in that directory is safe for use by others. The [`I'll take pkg over internal`](https://travisjeffery.com/b/2019/11/i-ll-take-pkg-over-internal/) blog post by Travis Jeffery provides a good overview of the `pkg` and `internal` directories and when it might make sense to use them.