topics/go/design/packaging/README.md
Package Oriented Design allows a developer to identify where a package belongs inside a Go project and the design guidelines the package must respect. It defines what a Go project is and how a Go project is structured. Finally, it improves communication between team members and promotes clean package design and project architecture that is discussable.
Design Philosophy On Packaging - William Kennedy
Package Oriented Design - William Kennedy
In an interview given to Brian Kernighan by Mihai Budiu in the year 2000, Brian was asked the following question:
“Can you tell us about the worse features of C, from your point of view”?
This was Brian’s response:
“I think that the real problem with C is that it doesn’t give you enough mechanisms for structuring really big programs, for creating "firewalls" within programs so you can keep the various pieces apart. It’s not that you can’t do all of these things, that you can’t simulate object-oriented programming or other methodology you want in C. You can simulate it, but the compiler, the language itself isn’t giving you any help.”
Kit Application
├── CONTRIBUTORS ├── cmd/
├── LICENSE ├── internal/
├── README.md │ └── platform/
├── cfg/ └── vendor/
├── examples/
├── log/
├── pool/
├── tcp/
├── timezone/
├── udp/
└── web/
vendor/
Good documentation for the vendor/ folder can be found in this Gopher Academy post by Daniel Theophanes. For the purpose of this post, all the source code for 3rd party packages need to be vendored (or copied) into the vendor/ folder. This includes packages that will be used from the company Kit project. Consider packages from the Kit project as 3rd party packages.
cmd/
All the programs this project owns belongs inside the cmd/ folder. The folders under cmd/ are always named for each program that will be built. Use the letter d at the end of a program folder to denote it as a daemon. Each folder has a matching source code file that contains the main package.
internal/
Packages that need to be imported by multiple programs within the project belong inside the internal/ folder. One benefit of using the name internal/ is that the project gets an extra level of protection from the compiler. No package outside of this project can import packages from inside of internal/. These packages are therefore internal to this project only.
internal/platform/
Packages that are foundational but specific to the project belong in the internal/platform/ folder. These would be packages that provide support for things like databases, authentication or even marshaling.
<u>Validate the location of a package.</u>
Kit
Application projects that exist.cmd/
internal/
internal/platform/
<u>Validate the dependency choices.</u>
All
internal/
cmd/internal/platform/
cmd/internal/<u>Validate the policies being imposed.</u>
Kit, internal/platform/
cmd/, internal/
<u>Validate how data is accepted/returned.</u>
All
<u>Validate how errors are handled.</u>
All
Kit
cmd/
internal/
internal/platform/
<u>Validate testing.</u>
cmd/
test folder for tests.kit/, internal/, internal/platform/
<u>Validate recovering panics.</u>
cmd/
kit/, internal/, internal/platform/
All material is licensed under the Apache License Version 2.0, January 2004.