You probably want go mod vendor. Emphasis mine:
The go mod vendor command constructs a directory named vendor in the main module’s root directory that contains copies of all packages needed to support builds and tests of packages in the main module. Packages that are only imported by tests of packages outside the main module are not included. As with go mod tidy and other module commands, build constraints except for ignore are not considered when constructing the vendor directory.
When vendoring is enabled, the go command will load packages from the vendor directory instead of downloading modules from their sources into the module cache and using packages those downloaded copies. See Vendoring for more information.
See also: what is the purpose of `go mod vendor` command?
Given a simple main.go that imports github.com/go-log/log/print
:
package main
import (
"github.com/go-log/log/print"
)
type MyLogger struct{}
func (l MyLogger) Print(v ...interface{}) {}
func (l MyLogger) Printf(format string, v ...interface{}) {}
func main() {
printer := print.New(MyLogger{})
printer.Log("Blah")
}
... running go mod vendor
will vendor those files and you will end up with the following in your vendor
folder:
|-github.com
| |-go-log
| | |-log
| | | |-LICENSE
| | | |-print
| | | | |-print.go
|-modules.txt
The next time you go build
, the version of print from the vendor
folder will be used instead.