Code Not Running?

Hello, I just received access to the beta and started poking around with a couple Go repos for CLI programs I have; nothing major, just minor tools/microservices. Despite the extension being installed by default for Go, I couldn’t figure out how to get it running despite going into the menu > run > run without debugging. The terminal doesn’t have Go installed in it so I’m wondering if the extension was only for the basic linting, go fmt, and such.

The docs didn’t seem to have much very clear on getting CLI-based programs to work and only had a web-based example where port forwarding was required to visit the site and play with the results.

Did I miss something in the docs? Do I need additional setup of the Codespace upon creation despite it recognizing that it needs the Go extension installed? I’ve never used VS Code before so please excuse my inexperience with it or the interface.

Unfortunately, the current default “kitchen sink” image you get in a Codespace does not have go in it, but this is something we should resolve very soon.

In the meantime you can either:

  • Run the following from a terminal once you’re in a Codespace to install everything:

    curl -sSL -o- "https://raw.githubusercontent.com/microsoft/vscode-dev-containers/master/script-library/go-debian.sh" | sudo bash -s -- 1.15 /usr/local/go /go codespace
    
  • … or add a custom container to your repository by copying the .devcontainer folder from here into your repository root: https://github.com/microsoft/vscode-dev-containers/tree/master/containers/go

1 Like

Go should now be in the default image for Codespaces!

Sorry for the late reply. I’m still having issues with this despite ensuring the Go extension is installed. Are there any troubleshooting steps I should go through?

Edit: Do I need to delete the Codespace and have it recreated to recognize the Go image?

Yeah the script I referenced would add it to an existing codespace, but the underlying image will not update automatically since this could break your existing setup. New codespaces will get the latest default image.

If you ran the script and the editor is not seeing Go, you can go to VS Code settings (via the gear in the lower left), select the “Remote” tab so the setting doesn’t get applied to your local machine.

Click on “edit in settings.json” and add the following and save:

"go.gopath": "/go",
"go.goroot": "/usr/local/go"