Dagang Wei
Dagang Wei

Reputation: 26548

How do I debug Go dependency packages?

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

Answers (3)

owlwalks
owlwalks

Reputation: 1681

You can use replace directive:

replace example.com/original/import/path => /your/forked/import/path

Upvotes: 15

Giulio Micheloni
Giulio Micheloni

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

Parham Alvani
Parham Alvani

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

Related Questions