There is an old project that does not support go mod, to compile it, a few things need to be done,
- execute the following command to turn off the go module,
go env -w GO111MODULE="off"
- copy the local vendor dependencies to ${GOROOT}/src dir, so when compiling, go will find these dependencies.
- There are maybe some third party dependencies, such as that from github.com or golang.org. You can do this,
cd ${GOPATH}/src
git clone xxx
in this way, we can put the dependencies manually under the GOPATH/src dir, so when compiling, go can find these dependencies of github.com from GOPATH/src dir.
4. Compiling with specifying GOOS and GOARCH environment can make the binary executable on corresponding platform.
GOOS=linux GOARCH=amd64 go build -o xxx main.go
Comparing to the GOPATH compilation, go module really brings great convenience to us developers. When GO111MODULE is off, go finds packages from vendor and GOPATH/src. Otherwise, packages only are loaded via the go.mod file. This article introduces the GOPATH compilation method.