Sunday, June 28, 2020

Setting up a Go project in Vscode

  

Here are the steps I followed to setup a Go project in Vscode:
1) Install Vscode Go plugin.
2) Create a project
3) I still had this error:
4) To fix this, I downloaded the go 1.15 separately.  
5) Set GOPATH - export PATH=$PATH:/usr/local/go/bin/go 

Even after this, I am still not able to run my go program directly from UI. I could only the go program from the terminal.

One of my friends who uses Vscode helped me run go programs from vscode. He suggested these additional steps:

1) Open settings in vscode

 


2) Search for "gopath" & open "settings.json"


 

3) Set goroot & gopath in this file

 


4) After this, I had to restart vscode. After restart, vscode threw some pop ups to install a few things & I proceeded with those:

 

Tools environment: GOPATH=/Users/babuneelam/Projects/GoProjects/go_path
Installing 1 tool at /Users/babuneelam/Projects/GoProjects/go_path/bin in module mode.
gopls  
Installing github.com/mdempsky/gocode SUCCEEDED
Installing github.com/uudashr/gopkgs/v2/cmd/gopkgs SUCCEEDED
Installing github.com/ramya-rao-a/go-outline SUCCEEDED
Installing golang.org/x/tools/gopls SUCCEEDED
All tools successfully installed. You are ready to Go :).
Installing github.com/acroca/go-symbols SUCCEEDED
Installing golang.org/x/tools/cmd/guru SUCCEEDED
Installing golang.org/x/tools/cmd/gorename SUCCEEDED
Installing github.com/cweill/gotests/... SUCCEEDED
Installing github.com/fatih/gomodifytags SUCCEEDED
Installing github.com/josharian/impl SUCCEEDED
Installing github.com/davidrjenni/reftools/cmd/fillstruct SUCCEEDED
Installing github.com/haya14busa/goplay/cmd/goplay SUCCEEDED
Installing github.com/godoctor/godoctor SUCCEEDED
Installing github.com/go-delve/delve/cmd/dlv SUCCEEDED
Installing github.com/stamblerre/gocode SUCCEEDED
Installing github.com/rogpeppe/godef SUCCEEDED
Installing github.com/sqs/goreturns SUCCEEDED
Installing golang.org/x/lint/golint SUCCEEDED
All tools successfully installed. You are ready to Go :).

Tools environment: GOPATH=/Users/babuneelam/Projects/GoProjects/go_path
Installing 1 tool at /Users/babuneelam/Projects/GoProjects/go_path/bin in module mode.
goimports
Installing golang.org/x/tools/cmd/goimports SUCCEEDED
All tools successfully installed. You are ready to Go :).

5) Run & Launch. We can also set breakpoints too now.


 

By setting up vscode, I could avoid paying for Goland/IntelliJ, atleasr for now :)

Hope this helps.



No comments:

UA-48797665-1