Windows10配置GO语言开发环境(Visual Studio Code)

GO安装包下载

https://golang.google.cn/

GO语言环境配置

https://github.com/golang/go/wiki/SettingGOPATH#windows

go 里面有两个非常重要的环境变量 GOROOT 和 GOPATH,其中 GOROOT 是安装 go 的路径,而 GOPATH 是我们定义的自己的工作空间。

管理员权限打开命令行提示符

Windows10配置GO语言开发环境(Visual Studio Code)_第1张图片

输入指令

setx GOPATH %USERPROFILE%\go

This will set the GOPATH to your [home folder]\go, such as C:\Users\yourusername\go
在这里插入图片描述

查看环境变量值

在这里插入图片描述

C:\Users\zhaojq>go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\zhaojq\AppData\Local\go-build
set GOENV=C:\Users\zhaojq\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\zhaojq\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=c:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\zhaojq\AppData\Local\Temp\go-build596256890=/tmp/go-build -gno-record-gcc-switches

VSCode配置GO开发环境

VSCode中配置GOPATH和GOROOT

文件 -> 首选项 -> 设置,配置用户JSON文件

{
    "workbench.colorTheme": "Solarized Dark",
    "files.autoSave": "onFocusChange",
    "editor.fontSize": 18,
    "go.goroot": "C:\\go",
    "go.gopath": "C:\\Users\\zhaojq\\go",
    "files.exclude": {
        "**/.classpath": true,
        "**/.project": true,
        "**/.settings": true,
        "**/.factorypath": true
    }
}

安装gocode

go get -u -v github.com/nsf/gocode

安装godef

go get -u -v github.com/rogpeppe/godef

安装golint

# 创建 $GOPATH/src/golang.org/x
cd $GOPATH/src/golang.org/x
git clone https://github.com/golang/tools.git
git clone https://github.com/golang/lint.git

# 完成以上步骤后,执行
go get golang.org/x/lint/golint

安装go-find-references

go get -u -v github.com/lukehoban/go-find-references

安装go-outline

go get -u -v github.com/lukehoban/go-outline

安装goreturns

go get -u -v sourcegraph.com/sqs/goreturns

安装gorename

go get -u -v golang.org/x/tools/cmd/gorename

安装gopkgs

go get -u -v github.com/tpng/gopkgs

安装go-symbols

go get -u -v github.com/newhook/go-symbols

测试程序

package main

import "fmt"

func main() {
	fmt.Println("hello world!")
}

在这里插入图片描述

你可能感兴趣的:(环境配置)