Search code examples
dockergogolanddelve

Debugging Go API with Delve and Docker - Can't reach API with Postman


I am trying to debug a Go API with Docker and Goland.

I followed this tutorial and I could make it work when I am debugging a Go App.

But my app is an API, so it starts, and I expect that when I make my request via Postman, my API should stop at a breakpoint.

What is happening is that the API is not responding, and is not invoked.

Here is the Goland App Log:

API server listening at: [::]:40000
[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.

[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
 - using env:   export GIN_MODE=release
 - using code:  gin.SetMode(gin.ReleaseMode)

[GIN-debug] GET    /operations/:operation_id/keys --> main.displayKeysList (5 handlers)
[GIN-debug] HEAD   /operations/:operation_id/keys --> main.main.func1 (4 handlers)
[GIN-debug] Listening and serving HTTP on :9999

It is telling me that my app is running on port 9999, but delve is running on port 40000.

I tried both ports 9999 and 40000 but none of them work for my request.

What am I missing?


Solution

  • Your application still runs and needs port 9999 to be opened and forwarded to make the requests to it.

    Port 40000 is used by Delve and you should connect with the IDE to the remote service to allow it to start/continue using a Go Remote run configuration.

    If you still have problems with this, either raise an issue on https://youtrack.jetbrains.com/issues/Go and provide more details about this, screenshots or code to replicate would be great to have, or ping us on Twitter/Gophers Slack in #goland channel.