protoc --go_out=plugins=grpc:./ *.proto
172-1-1-156:proto $ protoc --go_out=plugins=grpc:./ *.proto
--go_out: protoc-gen-go: plugins are not supported; use 'protoc --go-grpc_out=...' to generate gRPC
protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
*.proto
See https://grpc.io/docs/languages/go/quickstart/#regenerate-grpc-code for more information.
172-1-1-156:proto $ GO111MODULE=on go get -u github.com/golang/protobuf/protoc-gen-go@v1.3.5
go get: downgraded github.com/golang/protobuf v1.5.0 => v1.3.5
go get: downgraded google.golang.org/protobuf v1.26.0 => v1.26.0-rc.1
# trading-system/grpc/etc/proto
grpc/etc/proto/etc.pb.go:30:11: undefined: "github.com/golang/protobuf/proto".ProtoPackageIsVersion4
//我只用了如下方法
go get -u google.golang.org/grpc
go install github.com/golang/protobuf/protoc-gen-go
// 以下方法来自http://www.manongjc.com/detail/11-wgczdfriohrkgjm.html
GIT_TAG="v1.2.0" # change as needed
go get -d -u github.com/golang/protobuf/protoc-gen-go
git -C "$(go env GOPATH)"/src/github.com/golang/protobuf checkout $GIT_TAG
go install github.com/golang/protobuf/protoc-gen-go
*ApiGRPCServer does not implement "trading-system/grpc/api/proto".ApiServiceServer (missing "trading-system/grpc/api/proto".mustEmbedUnimplementedApiServiceServer method)
have mustEmbedUnimplementedApiServiceServer()
want "trading-system/grpc/api/proto".mustEmbedUnimplementedApiServiceServer()
protoc --go_out=plugins=grpc:./ *.proto
插件错误,目前google自己包不支持grpc插件功能
参考issue:https://github.com/golang/protobuf/issues/1070
错误提示
plugins are not supported; use 'protoc --go-grpc_out=...'
github.com/golang/protobuf/protoc-gen-go
版本兼容支持,目前以下版本是兼容的
关于go.mod文件,自动升级的问题
In Go 1.15 and lower, the -mod=mod flag was enabled by default, so updates were performed automatically. Since Go 1.16, the go command acts as if -mod=readonly were set instead: if any changes to go.mod are needed, the go command reports an error and suggests a fix
package proto.api;
option go_package = "./;proto";
package proto.api; 用于包装pb文件的方法,供client端调用,client端也需要有相同的命名。
rpc CreateAccount (AccountInfoRequest) returns (CommonResponse) {
}
```
对应:
func (c *apiServiceClient) CreateAccount(ctx context.Context, in *AccountInfoRequest, opts ...grpc.CallOption) (*CommonResponse, error) {
out := new(CommonResponse)
err := c.cc.Invoke(ctx, "/proto.api.ApiService/CreateAccount", in, out, opts...)//对应这里
if err != nil {
return nil, err
}
return out, nil
}
option go_package = “./;proto”;这个是为了本包的文件引用用的