Rules of Go-Lang Packaging

Based on experimentation and from looking at the language spec, I want to try to pin-down how Go packaging works.

Honestly, I haven’t found Go’s packaging and import mechanism that intuitive so far. It is possible that I’m just not viewing things right - maybe I’m too used to how things are done in languages like Python, Java and C++.

But it could also be I don’t have the full picture, because I’ve been reading the language spec, which leaves certain decisions open to the toolchain. 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 as far as I can tell.

 For a library

For executables

So folders are the unit-of-packaging and package names must match the containing folder names. Except for folders that contain executable main files.