安装go专用protoc生成器失败问题的解决方法

问题1

安装go的专用protoc生成器时,执行如下命令:

go get github.com/golang/protobuf/protoc-gen-go

报错如下:

C:\Users\无心>go get github.com/golang/protobuf/protoc-gen-go
go: go.mod file not found in current directory or any parent directory.
        'go get' is no longer supported outside a module.
        To build and install a command, use 'go install' with a version,
        like 'go install example.com/cmd@latest'
        For more information, see https://golang.org/doc/go-get-install-deprecation
        or run 'go help get' or 'go help install'.

解决方案

如果使用的windows系统安装,执行如下命令:

# 设置模块自动支持
go env -w GO111MODULE=auto

问题2

protoc-gen-go下载完毕后,执行安装,命令如下:

go build 

go install

报错如下:

C:\Users\无心\go\src\github.com\golang\protobuf\protoc-gen-go>go build
go: github.com/google/go-cmp@v0.5.5: Get "https://proxy.golang.org/github.com/google/go-cmp/@v/v0.5.5.mod": dial tcp 142.251.43.17:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
go: downloading google.golang.org/protobuf v1.26.0
go: github.com/google/go-cmp@v0.5.5: Get "https://proxy.golang.org/github.com/google/go-cmp/@v/v0.5.5.mod": dial tcp 142.251.43.17:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

解决方案

设置代理

go env -w GOPROXY=https://goproxy.cn

安装完成后,会在GOPATH/bin下生成 protoc-gen-go.exe 。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值