使用 Delve 和 Docker 调试 Go API - 使用 Postman 无法到达 API

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

我正在尝试使用 Docker 和 Goland 调试 Go API。

我关注了this tutorial,当我调试 Go 应用程序时,我可以使它工作。

但是我的应用程序是 API,所以它启动了,我希望当我通过 Postman 发出请求时,我的 API 应该在断点处停止。

发生的事情是 API 没有响应,也没有被调用。

这是 Goland 应用程序日志:

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

它告诉我我的应用程序 运行 在端口 9999 上,但是 delve 在端口 40000 上 运行。

我尝试了 9999 和 40000 这两个端口,但是 none 可以满足我的要求。

我错过了什么?

您的应用程序仍然 运行s 并且需要打开和转发端口 9999 以向它发出请求。

端口 40000 由 Delve 使用,您应该使用 IDE 连接到远程服务以允许它 start/continue 使用 Go Remote 运行 配置。

如果您对此仍有疑问,请在#goland 频道的 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 上提出问题。