-
Notifications
You must be signed in to change notification settings - Fork 433
Golang
Thang Chung edited this page Dec 26, 2022
·
2 revisions
Let give an example that we want to debug product
in the structure below
.
├── cmd
│ └── product
│ ├── config
│ │ └── config.go
│ ├── config.yml
│ └── main.go
├── docker
│ ├── Dockerfile-dev
│ └── Dockerfile-product
├── docker-compose.yaml
├── docs
│ └── readme.md
├── go.mod
├── go.sum
├── Makefile
├── pkg
│ └── readme.md
├── README.md
└── tools
└── readme.md
What we can do is create the config for it in .vscode/launch.json
with the content below
{
"version": "0.2.0",
"configurations": [
{
"name": "Product - Debug",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/product",
"showLog": true,
"logOutput": "debugger",
}
]
}
Notices: ${workspaceFolder}/cmd/product
should point to the service that you want to debug.
Then set the breaking points and start to debug it with dlv
which has already been there if you use devcontainer
in this repository.
// overcome VarArgs in wire
// variadic-functions => https://gobyexample.com/variadic-functions
func initApp(
ctx context.Context,
cfg *config.Config,
pg *postgres.Postgres,
amqpConn *amqp.Connection,
opts1 []pkgConsumer.Option,
opts []pkgPublisher.Option,
) (*App, error) {
// abc := make([]pkgPublisher.Option, 0)
// abc = append(abc, pkgPublisher.ExchangeName(""))
// abc = append(abc, pkgPublisher.BindingKey(""))
panic(wire.Build(New, pkgPublisher.RabbitMQProviderSet, pkgConsumer.ConsumerProviderSet, eventhandlers.BaristaOrderedEventHandlerSet))
}```