go

protobuf

go protobuf

Posted by Liangjf on October 4, 2019

go proto指定import路径

proto文件在import依赖包。需要在proto命令生成文件时,指明import的包的路径

demo:

syntax = "proto3";

package gateway;

import "google/api/annotations.proto";

message Message {
    string msg = 1;
}

service Gateway {
    rpc Echo (Message) returns (Message) {
        option (google.api.http) = {
            post: "/api/v1/echo"
            body: "*"
        };
    }
}

执行命令:

protoc --grpc-gateway_out=logtostderr=true:. gateway.proto

报错:

google/api/annotations.proto: File not found.
gateway.proto: Import "google/api/annotations.proto" was not found or had errors.


protoc -I . -I $GOPATH/pkg/mod/github.com/grpc-ecosystem/grpc-gateway@v1.9.6/third_party/googleapis  --grpc-gateway_out=logtostderr=true:. gateway.proto