title: Debug a Go application on Visual Studio Code
body: <p>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.</p>
  <p><a href="https://i.stack.imgur.com/ssJkg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ssJkg.png" alt="Tree" /></a></p>
  <p><strong>Running flow</strong>:<br />
  In order to run the server, I first run the following command on a terminal</p>
  <pre><code>go run -tags=jsoniter cmd/server/*
  </code></pre>
  <p>After that, I hit the API via Postman to run individual services.</p>
  <p><strong>Debugging flow:</strong><br />
  Likewise, I would like to debug the services (via API hit). After adding some breakpoints, I followed the instruction by creating a <code>launch.json</code> file in the <code>.vscode</code> directory.</p>
  <p>Here is the configuration in the <code>launch.json</code></p>
  <pre class="lang-json prettyprint-override"><code>{
              &quot;name&quot;: &quot;Launch Package&quot;,
              &quot;type&quot;: &quot;go&quot;,
              &quot;request&quot;: &quot;launch&quot;,
              &quot;mode&quot;: &quot;debug&quot;,
              &quot;program&quot;: &quot;cmd/server/&quot;,
              //&quot;host&quot;: &quot;127.0.0.1&quot;,
              //&quot;port&quot;: 8080,
          },
  </code></pre>
  <p>After setting up, I clicked &quot;Run&quot; to start the server, but it gave the following error: <code>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</code></p>
  <p>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</p>
  <pre><code>$go version
  &gt;go version go1.17.3 darwin/arm64
  </code></pre>
  <p><strong>Bonus</strong>: If I uncomment the two configuration lines <code>&quot;host&quot;</code> and <code>&quot;port&quot;</code>, 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.</p>
  <p><strong>Questions:</strong></p>
  <ul>
  <li>Is there anything wrong with my debugging? Currently, I have to debug by adding <code>log</code> into the code and tracking them. It's not the most efficient I reckon.</li>
  <li>If VCS does not work for me (unfortunately), would you suggest another IDE/approach for debugging?</li>
  </ul>
  <p><strong>Update</strong>: I tried this on GoLand as someone suggested it and it did not work for me as well. I received the same error</p>