eddycjy / blog

煎鱼的博客,有点忙,传送门:https://eddycjy.com
3.05k stars 429 forks source link

posts/go/grpc/2018-09-23-client-and-server/ #157

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

「连载二」gRPC Client and Server

https://eddycjy.com/posts/go/grpc/2018-09-23-client-and-server/

happychenleilei commented 2 years ago

go get -u github.com/golang/protobuf/protoc-gen-go 报错: go: module github.com/golang/protobuf is deprecated: Use the "google.golang.org/protobuf" module instead.

解决方案:go get -u google.golang.org/protobuf/cmd/protoc-gen-go@latest

happychenleilei commented 2 years ago

运行 protoc --go_out=. *.proto 报错: protoc-gen-go: unable to determine Go import path for "search.proto" Please specify either: • a "go_package" option in the .proto source file, or • a "M" argument on the command line.

解决方案: search.proto文件加入option go_package ="./";

BeardLeon commented 1 year ago

运行protoc --go-grpc_out=. *.proto 报错: protoc-gen-go-grpc: program not found or is not executable Please specify a program using absolute path or make sure the program is available in your PATH system variable --go-grpc_out: protoc-gen-go-grpc: Plugin failed with status code 1.

解决方案:go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest

qgwyspks commented 1 year ago

应该运行 protoc --go_out=. --go-grpc=. *.proto

abrahamhwj commented 1 year ago

https://grpc.io/docs/languages/go/quickstart/#regenerate-grpc-code

kangxuan commented 1 year ago

随着时间的推移,安装更新的protocolbuffers会出现一些问题: 比如 protocolbuffers 3.21.12 ,安装环境:MacOS

wget https://github.com/protocolbuffers/protobuf/releases/download/v21.12/protobuf-all-21.12.zip unzip protobuf-all-21.12.zip cd protobuf-all-21.12 ./configure && make && make install 注意这里如果报错:C compiler cannot create executables 我的问题没有按照Xcode,通过AppStore安装就能解决

安装 protoc-gen-go go install google.golang.org/protobuf/cmd/protoc-gen-go@latest

安装 protoc-gen-go-grpc go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest

生成 proto文件 cd proto && protoc --go_out=. --go-grpc_out=. *.proto 会生成2个文件:search.pb.go和search_grpc.pb.go 注意有报错:protoc-gen-go: unable to determine Go import path for "search.proto" 需要在search.proto文件中加入代码: option go_package ="./";

server.go pb.RegisterSearchServiceServer(server, &SearchService{})

报错:it has a non-exported method and is defined in a different package

解决方案:

type SearchService struct { pb.UnimplementedSearchServiceServer }