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.

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

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大