The invalid information that you have is that the package name must not match the directory name.
It is perfectly fine to use a package name other than a folder name. If you do this, you will still have to import the package based on the directory structure, but after importing you should refer to it by the name that you used in the package offer.
For example, if you have a folder $GOPATH/src/mypck , and there is a.go file in it:
package apple const Pi = 3.14
Using this package:
package main import ( "mypck" "fmt" ) func main() { fmt.Println(apple.Pi) }
Just as you are allowed to use relative imports, but it is not recommended, you can use other package names that contain their folder, but it is also not recommended to avoid further misunderstanding.
Note that the specification does not even require that all files belonging to the same package be in the same folder (but this may be an implementation requirement). Spec: Package Offer:
A set of files that have the same PackageName is an implementation of the package. An implementation may require that all source files for a package be in the same directory.
What use is this?
Simple Package Name - Go identifier :
identifier = letter { letter | unicode_digit } .
That allows you to use Unicode characters in identifiers, for example. Ξ±Ξ² is a valid identifier in Go. File and file names are not processed by Go, but by the operating system, and different file systems have different restrictions. In fact, there are many file systems that will not allow all valid Go identifiers as folder names, so you wonβt be able to name your packages, which would otherwise allow the language specification.
Thus, in one hand, not all valid Go identifiers may be valid folder names. On the other hand, not all valid folder names are valid Go identifiers, for example go-math is a valid folder name on most (all?) File systems, but it is not a valid Go identifier (since identifiers cannot contain dashes - ).
Having the ability to use package names other than their containing folders, you have the opportunity to really name your packages, which allows the language specification, regardless of the base operating system and file system, and place it in a folder with the name, the base OS and file system allow you to - regardless of the package name.