LoginSignup
3
4

More than 5 years have passed since last update.

Go & VSCode開発Debug環境構築

Posted at

準備

まずはGOの公式サイトからインストール。
https://golang.org/dl/
インストール完了あと、c:\go\bin をシステムの環境変数に追加します。

それからvscodeの中でGOの拡張機能を入れます。
image.png

それからvscodeの中でF1を押して、出たパネルに
Go: Install/Update toolsを入力する
image.png
すべてをチェックして、インストールする。

Hello World

main.go
package main

import (
    "fmt"
)

func main() {
    fmt.Print("Hello world")
}

Ctrl + Shift + Bで実行する。初めて実行する時は tasks.json を配置しないといけない。

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "run",
            "type": "shell",
            "command": "go",
            "args": [
                "run",
                "${file}"
            ]
        }
    ]
}

配置完了あと、hello worldは実行可能です。

Debug

さっきGo: Install/Update toolsした時、もしdlvが入ったらF5を押すだけでDebugモードに入れるが。もしdlvをインストールしていないなら、手動でインストールする必要があります。
https://github.com/go-delve/delve/tree/master/Documentation/installation
↑具体的なインストール方法
https://github.com/Microsoft/vscode-go/wiki/Debugging-Go-code-using-VS-Code
インストールしたあとlaunch.jsonをセットアップすればDebug可能です。

launch.json
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch",
            "type": "go",
            "request": "launch",
            "mode": "auto",
            "program": "${fileDirname}",
            "env": {},
            "args": []
        }
    ]
}
3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4