Rules of Go-Lang Packaging

Based on experimentation and from looking at the language spec, I want to try to define how Go packaging works. I haven’t found Go’s packaging and import mechanism that intuitive so far.  I think this is probably due to stale assumptions based on my experience in other languages like Python, Java and C++, and also for the fact that the language spec leaves certain decisions open to the toolchain. Plus, the toolchain provides several commands for building and running (build, install, and run), and several ways to specify what to build (by package, by file path or using wildcards).

So, here are the rules based on my current understanding. First, for a library:

Then for executables:

It’s actually quite simple, if you think about folders as the unit-of-packaging and make sure that you use package names that match the containing folder names, except for folders that contain executable main files.

This is just my current understanding, so if you think I have made a mistake, please do tell me.