My Go project depends on package example.com/foo
. I am using Go 1.12, so the dependency is automatically pulled in by Go modules. Now, there is an error happening inside of the dependency, I want to debug it by adding log or step by step execution. I can find the source code of the dependency on GitHub but I don't know how to fit it into my project, so that it replaces the dependency which was pulled in by Go modules.
First fetch all the dependency packages into the vendor
folder.
go mod vendor
Then, change the source code in that and build your project by specifying to look into vendor
folder.
go build -mod=vendor
or
go run -mode=vendor myapp.go
Go module fetches packages into $GOPATH/pkg/mod
you can change the source code there or using the vendor option of go mod to pull the packages into vendor folder and then start coding there.
You can use replace directive:
replace example.com/original/import/path => /your/forked/import/path