Reputation: 26548
Say 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. The dependency seems to have a bug, so I want to add logs in the source code.
I can find the source code of on GitHub but I don't know how to make it as part of my project for debugging purposes.
Upvotes: 21
Views: 6478
Reputation: 1681
You can use replace directive:
replace example.com/original/import/path => /your/forked/import/path
Upvotes: 15
Reputation: 1380
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 -mod=vendor myapp.go
Upvotes: 30
Reputation: 2440
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.
Upvotes: 8