golang help API

2022 Nov 08 See all posts


golang help API

I wanted to document some stuff which has been helpful to me in golang development.

adding code in dependency packages for debugging

Often we want to add some logs in the dependency code in a golang project. It's not as simple as directly editing the package contents and rebuilding the project. What we can do instead is to fetch the dependencies in a vendor folder and then build using that:

go mod vendor

## build
go build -mod=vendor
## or
go run -mod=vendor myapp.go

delve

while debugging a golang project, we utilise substitute-path in dlv/config.yml in the project root. This allows us to rewrite a source path stored in program's debug information.

substitute-path:
    - {from: github.com/ledgerwatch/erigon, to: /Users/sudeep/repos/cov-erigon}