You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 1.9 kB

12345678910111213141516171819202122232425262728293031323334
  1. # `/internal`
  2. Private application and library code. This is the code you don't want others importing in their applications or libraries. Note that this layout pattern is enforced by the Go compiler itself. See the Go 1.4 [`release notes`](https://golang.org/doc/go1.4#internalpackages) for more details. Note that you are not limited to the top level `internal` directory. You can have more than one `internal` directory at any level of your project tree.
  3. 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`).
  4. For example, if you have a directory structure like this:
  5. ```go
  6. myapp/
  7. internal/
  8. util.go
  9. main.go
  10. ```
  11. myapp/internal/util.go can only be referenced within the myapp module. For example, main.go can import "myapp/internal/util".
  12. But code from other modules cannot import myapp/internal. If you try to import "myapp/internal/util", the compiler will report an error:
  13. ```bash
  14. cannot use "myapp/internal/util" as external package name: myapp/internal/util.go: does not export package internal
  15. ```
  16. Examples:
  17. * https://github.com/hashicorp/terraform/tree/main/internal
  18. * https://github.com/influxdata/influxdb/tree/master/internal
  19. * https://github.com/perkeep/perkeep/tree/master/internal
  20. * https://github.com/jaegertracing/jaeger/tree/main/internal
  21. * https://github.com/moby/moby/tree/master/internal
  22. * https://github.com/satellity/satellity/tree/main/internal
  23. ## `/internal/pkg`
  24. Examples:
  25. * https://github.com/hashicorp/waypoint/tree/main/internal/pkg

openkf

Contributors (1)