Golang学习记录一 安装go,protoc
pre: Go Tour学习
首先是看了Go Tour上的基本语法讲解,还有在线的编程小例子。目前学到了这里https://tour.go-zh.org/concurrency/9 基本上学完了
go的安装
似乎是官网需要挂梯子,没有登上去。后面看着这个步骤https://blog.csdn.net/weixin_46609492/article/details/121436082安装的
- 先去下载: https://studygolang.com/dl
- 安装的时候会自动配好系统和用户环境变量
- cmd go --version检查ok
Protocol Buffer
在合适的位置新建一个文件夹
go mod init 这个文件夹
安装
go get -u github.com/golang/protobuf/proto
go get -u github.com/golang/protobuf/protoc-gen-go
报错go: module github.com/golang/protobuf/protoc-gen-go: Get “https://proxy.golang.org/github.com/golang/protobuf/protoc-gen-go/@v/list”: dial tcp (ip):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.
翻回去先安装git参考http://cd.itheima.com/news/20211208/163755.html
但是仍然会报这个错
查找之后换了GoProxy:
go env -w GOPROXY=https://goproxy.cn
然后
go get google.golang.org/protobuf/cmd/protoc-gen-go@v1.28
go get google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2
成功了 椰丝
emmm遇到了问题https://blog.csdn.net/suwei825/article/details/123770845和这个一样
发现GOPATH的bin里面没有protoc-gen-go-grpc.exe,执行命令
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2
把protoc-gen-go-grpc.exe和protoc-gen-go.exe复制到了go的bin里
执行protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative helloworld/helloworld.proto成功
后面的继续按照https://grpc.io/docs/languages/go/quickstart/#update-the-client进行 都很顺利