问题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 。