我怎样才能调试特定的功能?(How can I debug specific functions?)

编程入门 行业动态 更新时间:2024-10-09 19:23:20
我怎样才能调试特定的功能?(How can I debug specific functions?)

我有一个网站,有几个不同的功能。 我可以通过使用localhost:5000 /来访问我的网站,当我使用vscode-go调试器以调试模式运行它时,我得到以下消息API服务器正在侦听:127.0.0.1:52238

我有一个名称函数返回几个字符串,但我不能在调试模式下击中断点。 我在我的Name函数中放置了一个断点,并将该网址如下所示: 127.0.0.1 : 52238/ name,但它不会触及断点。 这里会发生什么? 我的代码如下,如果我正常运行应用程序,并把http:// localhost:5000 /名称,然后一切正常,但在调试模式下,这127.0.0.1:52238 /名称不会击中断点或页面。 我使用Go作为后端api,因此我需要点击url端点来查看发生了什么。 有没有办法可以使调试端口也是:5000

-- Main package main import ( "github.com/gorilla/mux" "runtime" "./Models" "./Controllers" ) func main() { Controllers.CircleRoutes(r) srv := &http.Server{ ReadTimeout: 20 * time.Second, WriteTimeout: 20 * time.Second, IdleTimeout: 120 * time.Second, Addr: ":5000", } srv.ListenAndServe() } // Circles Route package Controllers func Name(w http.ResponseWriter, r *http.Request) { var result string r.ParseForm() result = "Success" io.WriteString(w, result) } func CircleRoutes(r *mux.Router) { r.HandleFunc("/name", Name) }

I have a website that has several different functions . I can get to my website by using localhost:5000/ , when I run it in debug mode using vscode-go debugger I get the following message API server listening at: 127.0.0.1:52238

I have a Name function that returns several strings but I can not hit the breakpoint in debug mode . I put a breakpoint in my Name function and put the url as follows: 127.0.0.1:52238/name however it does not hit the breakpoint. What could be going on here ? My code is below if i run the application normally and put http://localhost:5000/name then everything works but in debug mode this 127.0.0.1:52238/name does not hit the breakpoint or page . I am using Go as a backend api so I'll need to hit url endpoints to see what's going on. Is there someway that I can make the debug port also :5000 ?

-- Main package main import ( "github.com/gorilla/mux" "runtime" "./Models" "./Controllers" ) func main() { Controllers.CircleRoutes(r) srv := &http.Server{ ReadTimeout: 20 * time.Second, WriteTimeout: 20 * time.Second, IdleTimeout: 120 * time.Second, Addr: ":5000", } srv.ListenAndServe() } // Circles Route package Controllers func Name(w http.ResponseWriter, r *http.Request) { var result string r.ParseForm() result = "Success" io.WriteString(w, result) } func CircleRoutes(r *mux.Router) { r.HandleFunc("/name", Name) }

最满意答案

看起来你正在使用vscode-go调试器。 您可以从vscode中的launch.json配置文件配置端口。

配置应该如下所示:

{ "version": "0.2.0", "configurations": [ { "name": "Launch", "type": "go", "request": "launch", "mode": "debug", "remotePath": "", "port": 2345, "host": "127.0.0.1", "program": "${workspaceRoot}", "env": { "GOPATH": <your GOPATH> }, "args": [], "showLog": true } ], "go.lintTool": "gometalinter" }

您可以从上面的设置更改端口。 要查找launch.json ,只需按ctrl+P并输入launch.json,它就会在您的vscode中显示搜索的下拉结果。

It looks you are using vscode-go debugger. You can configure the port from launch.json configuration file from your vscode.

The config should look like this:

{ "version": "0.2.0", "configurations": [ { "name": "Launch", "type": "go", "request": "launch", "mode": "debug", "remotePath": "", "port": 2345, "host": "127.0.0.1", "program": "${workspaceRoot}", "env": { "GOPATH": <your GOPATH> }, "args": [], "showLog": true } ], "go.lintTool": "gometalinter" }

You can change port from above settings. To find launch.json, just ctrl+P and type launch.json it will show dropdown result of search in your vscode.

更多推荐

本文发布于:2023-07-30 15:35:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1338819.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:功能   debug   functions   specific

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!