donglikuang8145 2018-05-22 05:41
浏览 16
已采纳

如何调试特定功能?

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)
 }
  • 写回答

1条回答 默认 最新

  • donglei7152 2018-05-22 09:09
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码