I am trying to debug a Go application on Visual Studio Code and it does not seem to work for me. Here is the directory tree.
Running flow:
In order to run the server, I first run the following command on a terminal
go run -tags=jsoniter cmd/server/*
After that, I hit the API via Postman to run individual services.
Debugging flow:
Likewise, I would like to debug the services (via API hit). After adding some breakpoints, I followed the instruction by creating a launch.json file in the .vscode directory.
Here is the configuration in the launch.json
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "cmd/server/",
//"host": "127.0.0.1",
//"port": 8080,
},
After setting up, I clicked "Run" to start the server, but it gave the following error: Failed to launch: could not launch process: can not run under Rosetta, check that the installed build of Go is right for your CPU architecture
I went on some websites and they said that it could be because I used the wrong Go version for the Apple M1 chip. I checked and I used the correct version as suggested but I still encountered the same issue
$go version
>go version go1.17.3 darwin/arm64
Bonus: If I uncomment the two configuration lines "host" and "port", the VCS will tell me that the file is wrong. When I comment on these two lines, it will try to start a server at a random port of 57169. But of course, it will fall into the above error.
Questions:
- Is there anything wrong with my debugging? Currently, I have to debug by adding
loginto the code and tracking them. It's not the most efficient I reckon. - If VCS does not work for me (unfortunately), would you suggest another IDE/approach for debugging?
Update: I tried this on GoLand as someone suggested it and it did not work for me as well. I received the same error





