Go packages
Everything in Go is delivered in the form of packages. A Go package is a Go source file that begins with the package
keyword, followed by the name of the package.
Note that packages can have structure. For example, the net
package has several subdirectories, named http
, mail
, rpc
, smtp
, textproto
, and url
, which should be imported as net/http
, net/mail
, net/rpc
, net/smtp
, net/textproto
, and net/url
, respectively.
Apart from the packages of the Go standard library, there are external packages that can be imported using their full address and that should be downloaded on the local machine, before their first use. One such example is https://github.com/spf13/cobra, which is stored in GitHub.
Packages are mainly used for grouping related functions, variables, and constants so that you can transfer them easily and use them in your own Go programs. Note that apart from the main
package, Go packages are not autonomous programs and cannot be compiled into...