Go&VScode 개발 Debug 환경 구축

4325 단어 GoVSCode

준비


우선 GO의 공식 사이트에서 설치합니다.
https://golang.org/dl/
설치가 완료되면 시스템 환경 변수에 c:\go\bin 를 추가합니다.
그리고 vscode에 GO의 확장 기능을 추가합니다.

그리고 vscode에서 F1을 누르고 나오는 패널에
입력Go: Install/Update tools
모두 확인하고 설치합니다.

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 toolsdlv 들어갔으면 F5만 누르면 디버그 모드로 들어갈 수 있었어요.만약 당신이 설치하지 않았다면 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": []
        }
    ]
}

좋은 웹페이지 즐겨찾기