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 项目文件夹

转载自:https://www.cnblogs.com/youjiao/p/12903223.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值