运行 evans(gRPC 客户端)如何正确?

How correctly run evans (gRPC client)?

我有一个 city.proto 文件,我在其中导入了一个名为 gogoproto. I created gRPC server and now I want to test it's rpc methods by evans gRPC 客户端的知名第三方包。

我使用了这样的 命令 但它引发了一个错误:

evans proto/city.proto --host localhost --port 8000

错误:

evans: failed to run REPL mode: failed to instantiate a new spec: failed to instantiate the spec from proto files: proto: failed to parse passed proto files: proto/city.proto:7:8: open github.com/gogo/p rotobuf/gogoproto/gogo.proto: The system cannot find the path specified.

city.proto:

syntax = "proto3";

package proto;

import "google/protobuf/wrappers.proto";
import "google/protobuf/timestamp.proto";
import "github.com/gogo/protobuf/gogoproto/gogo.proto";

option go_package = "./proto";

message City {
    uint64 id = 1 [
        json_name = "id",
        (gogoproto.jsontag) = "id"
    ];
    google.protobuf.Timestamp foundation_date = 2 [
        json_name = "foundation_date",
        (gogoproto.jsontag) = "foundation_date",
        (gogoproto.nullable) = false,
        (gogoproto.stdtime) = true
    ];
    google.protobuf.StringValue name = 3 [
        json_name = "name",
        (gogoproto.jsontag) = "name",
        (gogoproto.wktpointer) = true
    ];
    google.protobuf.StringValue country = 4 [
        json_name = "country",
        (gogoproto.jsontag) = "country",
        (gogoproto.wktpointer) = true
    ];
}

***

go版本:

go version go1.12.9 windows/amd64

协议版本:

libprotoc 3.11.4

埃文斯版:

0.9.0

很可能,我没有正确地尝试启动 REPL 模式。我假设该命令需要指定第三方原型文件所在目录的路径。我很迷惑。如何正确启动evans(gRPC客户端)?

为了运行埃文斯正确,需要使用--path指定正确的路径来搜索导入。 它几乎类似于protoc中的--proto_path。 例如,我们假设 github.com/gogo/protobuf 位于 /path/to/github.com/gogo/protobuf:

$ evans --path /path/to --path . proto/city.proto
$ evans --path /path/to --path . --proto proto/city.proto # Better

注意--path .也需要搜索proto/city.proto

由Google管理的知名protos如google/protobuf/wrappers.protogoogle/protobuf/timestamp.proto默认加载,但在其他情况下,我们必须指定正确的路径才能使用第三方原型。