GoLang

Resources

Setup GoLang (Visual Studio Code IDE)

  1. Download and Install Visual Studio Code.

    To check if it is installed properly
    at command prompt
    >> go version
    go version go1.15.6 windows/amd64

    To check for environment variables
    >> go env
    set GO111MODULE=
    set GOARCH=amd64
    set GOBIN=
    set GOCACHE=C:\Users\Bob\AppData\Local\go-build
    set GOENV=C:\Users\Bob\AppData\Roaming\go\env
    set GOEXE=.exe

    set GOPATH=D:\programs\golang
    ….

    GOPATH can be set from the Win10 environment variable.
    It is the directory of your workspace.
  2. Install GoLang extension.
    Menu -> View -> Extensions (Ctrl+Shift+X)
    Search for “go” and click install.
  3. Install Tools support GoLang
    Menu -> View -> Command Palette… (Ctrl+Shift+P)
    Search for “go: install/update tools”
    Select and install all the tools listed.

    Settings for Visual Studio Code.
    Search for “preferences: open settings (JSON)”
    Add in the settings from
    https://github.com/golang/tools/blob/master/gopls/doc/vscode.md
  4. Run GoLang
    >> go run main.go
  5. Build executable
    >> go build main.go
  6. Get auto import package
    >> go get golang.org/x/tools/cmd/goimports

Shortcut Command

  • Run Go code F5
  • Comment Ctrl+/
  • Format code Alt+Shift+F
  • Go To Definition F12 – Go to the source code of the type definition.
  • Peek Definition Alt+F12 – Bring up a Peek window with the type definition.
  • Go to References Shift+F12 – Show all references for the type.

Extension to install on Visual Studio Code

  • Go Lang – Go programming interfaces
  • Error Len – To highlight errors on the source codes.
  • Live Server – instant update to the change html codes, etc…
  • Live Share – code sharing with other programmers