这是我使用Go语言的第一天,我想调试一个简单的REST API。
package main
import (
"fmt"
"log"
"net/http"
)
func homePage(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Homepage EndPoint Hit")
}
func handleRequests() {
http.HandleFunc("/", homePage)
log.Fatal(http.ListenAndServe(":8080", nil))
}
func main() {
handleRequests()
}下面是我的调试配置
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch file",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceRoot}"
}
]
}settings.json是
{
"redhat.telemetry.enabled": true,
"vs-kubernetes": {
"vscode-kubernetes.helm-path.mac": "/Users/gsinha/.vs-kubernetes/tools/helm/darwin-amd64/helm"
},
"go.toolsManagement.autoUpdate": true,
"files.autoSave": "afterDelay",
"code-runner.clearPreviousOutput": true,
"code-runner.runInTerminal": true,
"code-runner.saveAllFilesBeforeRun": true
}当我尝试使用F5启动调试会话时,我得到了这个错误。
Starting: /Users/gsinha/go/bin/dlv-dap dap --listen=127.0.0.1:54320 --log-dest=3
DAP server listening at: 127.0.0.1:54320
Build Error: go build -o /Users/gsinha/go/src/rest/__debug_bin -gcflags all=-N -l /Users/gsinha/go/src/rest
go tool: no such tool "compile"
go tool: no such tool "compile"
go tool: no such tool "compile"
go tool: no such tool "compile" (exit status 2)我可以运行应用程序,但当我尝试启动调试会话时,它意外失败。
发布于 2021-09-01 02:01:56
检查您的go env,compile文件应该在路径GOTOOLDIR中。如果没有,请检查您的go安装。
也许会有帮助:All of a sudden go tool: no such tool "compile"
-更新
这应该是一个环境问题。
你能用vscode内部终端检查go env和go build吗?
你有没有在vscode中选择过go sdk版本?
https://stackoverflow.com/questions/69006471
复制相似问题