5

Update: Changed ${workspaceRoot} to ${workspaceRoot}/project_folder to get it to work.


I am just starting to learning Go and want to run it from Visual Studio Code.

I have this simple program:

package main

import "fmt"

func main() {
    fmt.Println("Hello World!")
}

I installed the Go extension from the marketplace: https://marketplace.visualstudio.com/items?itemName=lukehoban.Go

I also got the Delve debugger from here using go get: https://github.com/derekparker/delve

To try and run the code, I do this in Visual Studio Code:

  • I click on my file with the above code main.go
  • Go to the Debug tab
  • Click Launch (after generating the launch.json file)

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch",
            "type": "go",
            "request": "launch",
            "mode": "debug",
            "remotePath": "",
            "port": 2345,
            "host": "127.0.0.1",
            "program": "${workspaceRoot}",
            "env": {},
            "args": []
        }
    ]
}

Finally, I get this error:

can't load package: package github.com/mo: no buildable Go source files in C:\Users\Fazil\Documents\Workspace\Go\src\github.com\mo
exit status 1

Am I supposed to include something else? Any help would be appreciated, thank you!

3
  • 1
    Compile on the command line. Commented Jun 2, 2016 at 7:12
  • 3
    Also, make sure that the GOPATH and GOROOT environment variables are correct. Commented Jun 2, 2016 at 11:22
  • 2
    Turns out I had to add my folder in the 'launch.json' file. So I changed ${workspaceRoot} to ${workspaceRoot}/folder. Thank you both, however. I was able to learn how to compile from command line and more about the environment variables for Go. Commented Jun 2, 2016 at 12:13

1 Answer 1

1

I know you've already got it working by changing your working folder to the actual project folder, but here's the clue that should have helped

can't load package: package github.com/mo

github.com/mo is your username, not the project folder - Go is trying to run one folder up. You should always see github.com/mo/PROJECT

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.