Go 问题集锦
一、命令行报错
1. Protocol-Buffers 的安装
由于 Protocol-Buffers 不支持Go语言,使用时需要安装 protobuf-go,Github传送门。
Clone完毕后,在 \cmd\protoc-gen-go 路径下可以找到 main.go 文件。在此路径下打开命令行,使用 go build 命令执行。
go build main.go
go: github.com/golang/protobuf@v1.5.0: Get "https://proxy.golang.org/github.com/golang/protobuf/@v/v1.5.0.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: github.com/golang/protobuf@v1.5.0: Get “https://proxy.golang.org/github.com/golang/protobuf/@v/v1.5.0.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命令查看当前的配置,发现Go默认的代理网站在外网,国内无法访问到。需要修改代理网站:
go env -w GOPROXY=https://goproxy.cn,direct
修改完成后重新执行 go build 命令,成功生成 main.exe 文件。