Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging Go dependency packages?

Tags:

go

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. That dependency contains errors that I want to debug by adding logs or with 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.

like image 933
Dagang Avatar asked Jun 29 '19 13:06

Dagang


People also ask

How do I debug a go program?

To debug a program, execute the dlv debug command. Attach the filename at the end of this command, and debugging will start. For example, if you want to debug the main.go file, run the command dlv debug main.go . It is also known as “delve server” because this is a running process waiting for instructions.

How do you add a breakpoint in Golang?

Setting breakpointsSet a breakpoint at the TestFind function: (gdb) b 'regexp. TestFind' Breakpoint 1 at 0x424908: file /home/user/go/src/regexp/find_test.go, line 148. the one marked with the * is the current goroutine.

What is dependency management in Golang?

In Go, you manage dependencies as modules that contain the packages you import. This process is supported by: A decentralized system for publishing modules and retrieving their code. Developers make their modules available for other developers to use from their own repository and publish with a version number.


1 Answers

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
like image 163
Giulio Micheloni Avatar answered Sep 30 '22 22:09

Giulio Micheloni