VSCode搭建Go开发环境

博客

环境变量

linux 下环境变量

  • GOROOT(安装目录)、 GOPATH(工作目录)、GOBIN(可执行文件目录)、 PATH(环境变量)
vi /etc/profile

# Go setting
export GOROOT=/usr/local/go 
export GOPATH=~/golib:~/goproject
export GOBIN=~/gobin 
export PATH=$PATH:$GOROOT/bin:$GOBIN

配置

  • launch.json是vscode用于调试的配置文件,比如指定调试语言环境,指定调试类型等等。内容示例如下:
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "LaunchGo",
            "type": "go",
            "request": "launch",
            "mode": "debug",
            "remotePath": "",
            "port": 5546,
            "host": "127.0.0.1",
            "program": "${file}", //这个配置成你要调试的文件、${file}当前打开的文件
            "env": {
                "INFLUXDB_PW":"influxinflux",
                "GOPATH": "D:/go-workspace",
                "GOROOT": "D:/Go"
            },
            "args": ["--influxdb.username=influx",
                    "--influxdb.database=prometheus","--influxdb-url=http://10.130.135.79:8086/"],
            //"showLog": true
        }
    ]
}

go mod download 下载模块到本地缓存,缓存路径是 $GOPATH/pkg/mod/cache

猜你喜欢

转载自blog.csdn.net/thebigdipperbdx/article/details/111996424