2.6 Packages and Files
Packages in Go serve the same purposes as libraries or modules
in other languages, supporting modularity, encapsulation, separate compilation,
and reuse. The source code for a package resides in one or more
.go
files, usually in a directory whose name ends with the
import path; for instance, the files of the gopl.io/ch1/helloworld
package are
stored in directory $GOPATH/src/gopl.io/ch1/helloworld
.
Each package serves as a separate name space for its declarations.
Within the image
package, for example, the identifier
Decode
refers to a different function than does the same identifier
in the unicode/utf16
package.
To refer to a function from
outside its package, we must qualify the identifier to make explicit whether ...
Get The Go Programming Language now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.