我喜欢能够做非常简单的事情,等待客户端连接到 dlv 调试器,然后再继续代码但没有成功。我有简单的 go 服务器:
package main
import (
"fmt"
"net/http"
)
func hello(w http.ResponseWriter, req *http.Request) {
fmt.Fprintf(w, "hello\n")
}
func headers(w http.ResponseWriter, req *http.Request) {
for name, headers := range req.Header {
for _, h := range headers {
fmt.Fprintf(w, "%v: %v\n", name, h)
}
}
}
func main() {
fmt.Println("server started now!")
http.HandleFunc("/hello", hello)
http.HandleFunc("/headers", headers)
http.ListenAndServe(":8090", nil)
}
我像这样在 linux 机器上启动服务器:
vagrant@vagrant:~/go_dev/very_simple_server_dir$ dlv debug /home/vagrant/go_dev/very_simple_server_dir/very_simple_server.go --headless --listen=:3000 --log
API server listening at: [::]:3000
2022-10-31T06:18:47Z warning layer=rpc Listening for remote connections (connections are not authenticated nor encrypted)
2022-10-31T06:18:47Z info layer=debugger launching process with args: [/home/vagrant/go_dev/very_simple_server_dir/__debug_bin]
2022-10-31T06:18:47Z warning layer=debugger can't find build-id note on binary
在 visual studio 代码中,launch.json 如下所示:
"version": "0.2.0",
"configurations": [
{
"name": "Connect to server",
"type": "go",
"request": "attach",
"mode": "remote",
"remotePath": "/home/vagrant/go_dev/very_simple_server_dir/",
"cwd" : "${workspaceFolder}",
"port": 3000,
"host": "127.0.0.1",
"trace": "verbose",
"asRoot": true,
}
]
它可以很好地连接到远程服务器问题是我喜欢 dlv 调试服务器在执行 go 代码之前等待客户端连接。我希望能够在 func main() 第二行中设置断点
我怎样才能做到这一点 ?
杨__羊羊
相关分类