vscode 搭建 golang 开发环境
使用软件
- go1.14.3.windows-amd64.msi
https:
//golang.org/dl/
- vscode
https:
//code.visualstudio.com/
- git https://gitforwindows.org/
go1.14.3 安装后已经自动配置相关环境变量
在cmd中用命令 go env 查看go环境变量
vscode添加go插件
这时就可以 写一个 Hello World ,然后运行
hello.go
package main import "fmt" func main() { fmt.Printf("Hello word") }
保存的时候vscode右下角提示,需要安装依赖包
满以为,少啥咱就安啥,即然有 Install All 那就全要吧
结果
Installing github.com/mdempsky/gocode FAILED Installing github.com/uudashr/gopkgs/v2/cmd/gopkgs FAILED Installing github.com/ramya-rao-a/go-outline FAILED Installing github.com/acroca/go-symbols FAILED Installing golang.org/x/tools/cmd/guru FAILED Installing golang.org/x/tools/cmd/gorename FAILED Installing github.com/cweill/gotests/... FAILED Installing github.com/fatih/gomodifytags FAILED Installing github.com/josharian/impl FAILED Installing github.com/davidrjenni/reftools/cmd/fillstruct FAILED Installing github.com/haya14busa/goplay/cmd/goplay FAILED Installing github.com/godoctor/godoctor FAILED Installing github.com/go-delve/delve/cmd/dlv FAILED Installing github.com/stamblerre/gocode FAILED Installing github.com/rogpeppe/godef FAILED Installing github.com/sqs/goreturns FAILED Installing golang.org/x/lint/golint FAILED
没有一个能安装成功的
尝试过用git一个一个下载,安装时包依赖着包还找不到包的痛苦。
找到这么一个东东
https://goproxy.io/zh/ 一个全球代理为 Go 模块而生
按说明配置 go 1.13 及以上
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.io,direct
go 1.12及以下
# 启用 Go Modules 功能
export GO111MODULE=on
# 配置 GOPROXY 环境变量
export GOPROXY=https://goproxy.io
重新打开Vscode -> install all
OK!
报 go: cannot find main module; see 'go help modules' 问题
终端进入项目所在上级目录 执行 go mod init 项目文件夹