Go supports modules since v1.11+.
Go modules require that GOPATH is empty => unset GOTPATH
Run go mod init {module name}
to create a go.mod file for the current directory.
For example go mod init github.com/brutella/dnssd
creates the following content.
# go.mod
module github.com/brutella/dnssd
require (
github.com/miekg/dns v1.1.1
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9 // indirect
golang.org/x/net v0.0.0-20181201002055-351d144fa1fc
golang.org/x/sys v0.0.0-20181206074257-70b957f3b65e // indirect
)
Run go get -v
to fetch the modules defined in go.mod
.
Building the project automatically fetches the dependencies.
You can replace a dependency by using the replace keyboard like so
# go.mod
…
replace github.com/miekg/dns v1.1.1 => github.com/brutella/dns v1.0.0