Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
utterances-bot opened this issue Jan 20, 2022 · 6 comments
Open

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

utterances-bot opened this issue Jan 20, 2022 · 6 comments

Comments

@utterances-bot
Copy link

「连载二」gRPC Client and Server

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

Copy link

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

Copy link

运行 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 ="./";

Copy link

运行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

Copy link

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

Copy link

Copy link

kangxuan commented Mar 9, 2023

随着时间的推移,安装更新的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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants