Golang + VsCode
Go to file Use this template
2025-06-06 22:27:24 +02:00
.vscode launch.json and build tasks.json 2025-06-06 22:27:24 +02:00
.gitignore launch.json and build tasks.json 2025-06-06 22:27:24 +02:00
go.mod code & readme 2024-05-06 13:25:41 +02:00
hello.go code & readme 2024-05-06 13:25:41 +02:00
LICENSE NON-AI License 2024-11-27 11:03:16 +01:00
README.md launch.json and build tasks.json 2025-06-06 22:27:24 +02:00

A simple helloworld for Golang in VsCode.

Golang the compiler

Download Golang installer. A least on Mac the installer shall be able to deal with updating OS PATH environment variable with $GOPATH/bin.

Debugger

go install -v github.com/go-delve/delve/cmd/dlv@latest 

To install / update the goTools in VsCode:

Click cmd+shift+p and search for Go: Install/Update tools

VsCode IDE

  • Install Visual Studio Code
  • golang extension To launch VS Code Quick Open press (Ctrl + P), type: ext install Go, hit enter. Follow basic instructions.

The Project

Inside Visual Studio Code Open Folder Ctrl + Shift + E , e.g.: $USER\code\hello\. Then Open hello.go from that folder. Or make new file (Ctrl + N) and save it on this folder:

package main

import "fmt"

func main() {
	name := "World"
	fmt.Println(getGreeting(name))
}

func getGreeting(name string) string {
	return fmt.Sprintf("Hello, %s!", name)
}

Some useful hotkeys:

  • Ctrl + Shift + D - Open Debugger
  • F9 - set or toggle Breakpoint. Try this line name := "World"
  • F5 - Start Debugging or to Run the Application. If asked to select environment: select Go
  • F10 - Step Over
  • F11 - Step Into
  • Shift + F11 - Step Out
  • Shift + F5 - Stop Debugging
  • Ctrl + Shift + F5 - Restart Debugging

Typical aka untouched launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch",
            "type": "go",
            "request": "launch",
            "mode": "debug",
            "program": "${workspaceRoot}",
            "env": {},
            "args": [],
            "showLog": true,
        }
    ]
}

Custom build task

Create tasks.json:

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "go build",
      "type": "shell",
      "command": "go build -o bin/tui ./...", 
      "group": "build",
      "problemMatcher": ["$go"],
    }
  ]
}

Add this line to the desired run command in your launch.json

"preLaunchTask": "go build",