-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can I debug projects with this structure in VSCODE? #215
Comments
@adrianescat not an VSCode expert, but will look for a solution. if anybody wants to help that'll be cool too :) |
@adrianescat, try to split debug into build+exec( // https://code.visualstudio.com/docs/editor/debugging#_launchjson-attributes
{
"version": "0.2.0",
"configurations": [
{ /* Debug Exec (faster launch) + visible build output in terminal */
"name": "Debug Exec (faster launch)",
"type": "go",
"request": "launch",
"mode": "exec",
"preLaunchTask": "build", // <-- task build dependency
"program": "${workspaceRoot}/web",
},
]
}
// https://code.visualstudio.com/docs/editor/tasks
{
"version": "2.0.0",
"type": "shell",
"command": "go",
"cwd": "${workspaceFolder}", // <-- should allow resource usage (in theory)
"problemMatcher": [ "$go" ],
"presentation": {
"clear": true,
"reveal": "silent",
},
"tasks": [
{ /* build */
"label": "build",
"group": "build",
"args": [
"build",
"-v", "-x", "-gcflags='all=-N -l'", "-ldflags='-extldflags=-static'",
"-o=web",
"./cmd/web/"
],
},
],
}
package main
import (
"fmt"
"os"
)
func main() {
if _, err := os.Stat("readme.md"); err == nil { // project's root readme
fmt.Println("File exists\n") // <-- works!
} else {
fmt.Println("File does not exist\n")
}
} debug console:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey! I have installed delve, and is running fine on my PC. I'm trying to use this config in the
launch.json
:I have the main
.go
files inside thecmd/web
folder. The problem is that I have helpers, dbmodels, error handling insideinternal
. folder too.vscode starts the app correctly, but as soon as it requires things from internal or other folders in this structure outside
/cmd/web
it starts getting errors. It's like the packages imports are not working correctly. If I put everything inside the/cmd/web
folder I can debug and put breakpoints in the whole appHow do you debug web API's with this structure?
The text was updated successfully, but these errors were encountered: