GO-PACKAGES(7)
β¨ NAME β¨
packages β package lists and patterns π«Ά
okay bestie, this is the page from the Go programming tools and commands manual that explains how the go command figures out which packages you're even talking about. it's giving "index of every way to point at code" and honestly? iconic. let's get into it π
πΈ DESCRIPTION πΈ
so, a ton of commands work on a whole set of packages at once, like this:
go <action> [packages]
usually that <packages> is a list of package patterns, and a pattern can take several forms:
- a relative or absolute path to a file system directory, which can contain
...wildcard elements - an import path, which can also contain
...wildcard elements - a reserved name that expands to a set of packages
- a list of files
and if you don't hand it any import paths at all, the action just applies to the package in the current directory. lowkey convenient, fr fr β¨
those ... elements inside filesystem or import paths expand to match 0 or more path elements. the specific rules are below, don't skip them π
π File system patterns
patterns that begin with a file system root β like / on Unixes, or a volume name like C: on Windows β get interpreted as absolute file system paths. patterns that begin with a . or .. element get interpreted as relative file system paths. either way, file system paths denote the package contained within the given directory. simple as that π
relative paths are also a cute shorthand on the command line. say you're working in the directory containing the code imported as unicode and you wanna run the tests for unicode/utf8 β you can just type go test ./utf8 instead of specifying the whole entire full path. and in the reverse situation, go test .. will test unicode from the unicode/utf8 directory. relative patterns are allowed too, like go test ./... to test all subdirectories. so handy π
now here's the part where file system patterns expanded with the ... wildcard exclude the following:
- directories named
vendor - directories named
testdata - files and directories with names beginning with
_or. - directories that contain a
go.modfile - directories matching an ignore directive in a module's
go.modfile
want them included anyway? you can, by either using them in the prefix, or changing into those directories. for example, ./... won't match a ./testdata/foo package, but ./testdata/... will. main character problem-solving energy π
directories containing other go modules β which, remember, are denoted by the presence of a go.mod file β can only be matched by changing the working directory into module.
π¦ Import path patterns
patterns may also be import paths, as described in go help importpath. import path patterns match the packages from modules in the build list. and what's the build list? it's the list of module versions used for a build. see https://go.dev/ref/mod#glos-build-list for more details. π
some commands accept versioned package patterns, such as:
example.com/my/module@v1.2.3
these describe the matching package at the given version, independent of the versions used by the current module. so you can β¨specifyβ¨ ngl.
import path patterns may also use a ... wildcard, such as example.com/my/module/..., and that can be combined with the version specifier too, like example.com/my/module/...@latest. obsessed with the flexibility honestly.
import path pattern expansion with ... depends on context:
prefix/...matches all packages in modules in the build list that share the prefix, even if they belong to different modules- patterns that include a version specifier, such as in
prefix/...@latest, only match packages from the module thatprefixbelongs to
π Reserved names
the following reserved names each expand to a set of packages:
workexpands to all packages in the main module (or workspace modules)toolexpands to the tools defined in the current module'sgo.modfileallexpands to all packages in the main module (or workspace modules) and their dependencies, including dependencies needed by tests of any of those. and in the legacy GOPATH mode?allexpands to all packages found in all the GOPATH trees πstdexpands to all the packages in the standard library and their internal librariescmdexpands to the Go repository's commands and their internal libraries
π List of .go files
if your pattern is a list of Go files rather than a complete package, the go command synthesizes a virtual package named command-line-arguments containing just the given files. but bestie, in most cases doing this is an error β like with go build main.go or go build *.go. π
instead, prefer to operate on complete packages (directories), such as:
go build .
periodt. that's the move π
π§ Package names
packages are identified by their import path. import paths for packages in the standard library use their relative path under $GOROOT/src. import paths for all other packages are a combination of their module name and their relative directory path within the module. and within a program, all packages must be identified by a unique import path. no duplicates allowed, we don't do that here π
packages also have names, declared with the package keyword in a .go file, and used as the identifier when imported by another package. by convention, the names of importable packages match the last element of their import path β generally the name of the directory containing the package. cute, consistent, chef's kiss π
package names do not have to be unique within a module, but packages that share the same name can't be imported together without one of them being aliased to a different name. so choose your aliases wisely β¨
since the go command primarily operates on directories, all non test .go files within a directory (excluding subdirectories) should share the same package declaration. test files may suffix their package declaration with _test, and tests in these files are compiled as a separate package and don't have access to unexported identifiers of their corresponding package. see go help test and go help testflag for details π
the following package names have special meanings:
maindenotes the top-level package in a stand-alone executable. andmainpackages cannot be imported. not even a little bit π ββοΈdocumentationindicates documentation for a non-Go program in the directory. files in packagedocumentationare ignored by the go command_testβ that's the suffix in*_test.gofiles. these form a separate test package that only has access to the colocated package's exported identifiers. seego doc testingfor details
for more information about import paths, see go help importpath. π
π AUTHOR π
this manual page was created using help2man and afterwards updating the output. it is maintained by the Debian Go Compiler Team <team+go-compiler@tracker.debian.org> for the Debian project (and may be used by others).
and that's the whole vibe check, bestie β this one's from Go 1.27, dated August 2026, and it lives in section 7 of the manual. go forth and point at packages correctly π«Άπ
π¦ where this page comes from
- ubuntu stonking: golang-go 2:1.27~1 Β· Go
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms