diff --git a/pkg/README.md b/pkg/README.md index de411574..126b894c 100644 --- a/pkg/README.md +++ b/pkg/README.md @@ -1,6 +1,10 @@ # `/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. +`/pkg` directory contains specific code which is allowed use by external applications (e.g., `example.com/user/project/pkg/mypubliclib`). **But most of gophers doesn't like it**, since this external packages can be stored as another repo (f.e. you have `superapp` wrtitten in go, which provides some api, so you can put your go client to `example.com/user/go-superapp` as well as providing client apis written in other lang, f.e. `example.com/user/py-superapp`), which is way more consistent structure, than storing client libraries in this directory. + +**Note, that this directory should be avoided!** For client libs you can put them to some another place, for utilities, as well, store utils somwhere else (btw, try not to creacte `utils` packages as well). This directory exists here **only** to explain, why it exists in another projects like kubernetes, traefik and more more else. The fact that so popular projects like kubernetes have this dir doesn't meant that you are required to use it in your fresh project. + +Typically, other projects that you don't own can 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. It's also a way to group Go code in one place when your root directory contains lots of non-Go components and directories making it easier to run various Go tools (as mentioned in these talks: [`Best Practices for Industrial Programming`](https://www.youtube.com/watch?v=PTE4VJIdHPg) from GopherCon EU 2018, [GopherCon 2018: Kat Zien - How Do You Structure Your Go Apps](https://www.youtube.com/watch?v=oL6JBUk6tj0) and [GoLab 2018 - Massimiliano Pippi - Project layout patterns in Go](https://www.youtube.com/watch?v=3gQa1LWwuzk)).