Install Third Party Packages
go get gopkg.in/mgo.v2
The above command in the terminal will install “mgo”, a third-party Go driver package for MongoDB, into your GOPATH, which can be used across the projects put on the GOPATH directory.
After installing the mgo, put the import statement in your programs for reusing the code, as shown below:
import ( "gopkg.in/mgo.v2" "gopkg.in/mgo.v2/bson" )
The MongoDB driver, mgo, provides two packages that we have imported in the above import statement.
When using go get to install third-party packages, it is common for a package to be referenced by its canonical path. That path can also be a path to a public project hosted in a code repository such as GitHub.
As such, if you want to import the flect package, you would use the full canonical path:
$ go get github.com/gobuffalo/flect
The go get tool will find the package on GitHub in this case and install it into your $GOPATH. For this example the code would be installed in this directory:
The original authors are often updating packages to address bugs or add new features. When this happens, you may want to use the latest version of that package to take advantage of the new features or resolved bugs.
To update a package, you can use the -u flag with the go get command:
$ go get -u github.com/gobuffalo/flect
This command will also have Go install the package if it is not found locally. If it is already installed, Go will attempt to update the package to the latest version.
The go get command always retrieves the latest version of the package available.