Building packages
The Go tools reduce the complexity of compiling your code by applying certain conventions and sensible defaults. Although a full discussion of Go's build tool is beyond the scope of this section (or chapter), it is useful to understand the purpose and use of the build
and install
tools. In general, the use of the build and install tools is as follows:
$> go build [<package import path>]
The import path
can be explicitly provided or omitted altogether. The build
tool accepts the import path
expressed as either fully qualified or relative paths. Given a properly setup workspace, the following are all equivalent ways to compile package volt
, from the earlier example:
$> cd $GOPATH/src/github.com/vladimirvivien/learning-go $> go build ./ch06/volt $> cd $GOPATH/src/github.com/vladimirvivien/learning-go/ch06 $> go build ./volt $> cd $GOPATH/src/github.com/vladimirvivien/learning-go/ch06/volt $> go build . $> cd $GOPATH...