安装go vscode git
设置windows用户环境变量
GOROOT:golang安装目录
GOPATH:存放sdk以外的第三方类库、收藏可复用的代码
GOPATH目录约定有三个子目录:src、pkg、bin。src存放源代码(比如:.go .c .h .s等) 按照golang默认约定,go run,go install等命令的当前工作路径(即在此路径下执行上述命令);pkg编译时生成的中间文件(比如:.a)golang编译包时;bin编译后生成的可执行文件(为了方便,可以把此目录加入到PATH变量中,如果有多个gopath,那么使用{GOPATH/bin:}/bin添加所有的bin目录)
配置go env
# 打开git bash,键入以下命令
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
vscode配置
# 安装扩展:go和code runner
# 键入ctrl+shift+p 搜:go:install/update
# 选择所有下拉框,点击确定开始安装
# vscode输出以下信息即完成
Tools environment: GOPATH=D:\Dev_Go\GoPath;D:\Dev_Go\workspace
Installing 7 tools at D:\Dev_Go\GoPath\bin;D:\Dev_Go\workspace\bin in module mode.
gotests
gomodifytags
impl
goplay
dlv
staticcheck
gopls
Installing github.com/cweill/gotests/gotests@latest (D:\Dev_Go\GoPath\bin\gotests.exe) SUCCEEDED
Installing github.com/fatih/gomodifytags@latest (D:\Dev_Go\GoPath\bin\gomodifytags.exe) SUCCEEDED
Installing github.com/josharian/impl@latest (D:\Dev_Go\GoPath\bin\impl.exe) SUCCEEDED
Installing github.com/haya14busa/goplay/cmd/goplay@latest (D:\Dev_Go\GoPath\bin\goplay.exe) SUCCEEDED
Installing github.com/go-delve/delve/cmd/dlv@latest (D:\Dev_Go\GoPath\bin\dlv.exe) SUCCEEDED
Installing honnef.co/go/tools/cmd/staticcheck@latest (D:\Dev_Go\GoPath\bin\staticcheck.exe) SUCCEEDED
Installing golang.org/x/tools/gopls@latest (D:\Dev_Go\GoPath\bin\gopls.exe) SUCCEEDED
All tools successfully installed. You are ready to Go. :)