gRPC 说一个函数 "not implemented",其余都很好

gRPC says one function "not implemented", rest are fine

所有功能都是在同一时间完成的,并且按预期工作。我可以在本地给他们打电话,他们都能正常工作。但是 gRPC 不会调用 List().

rpc error: code = Unimplemented desc = method List not implemented

我试过删除 pb.go 文件、重命名函数等。仔细检查了我的 return 类型,尝试 return pointers/non-pointers。只有 List() 不起作用。它 return 是一个空的 ResponseCollection

这是我的 .proto:

syntax = "proto3";
package service;

message Response {
    bool IsMe = 1;
    bool Response = 2;
    string Message = 3; 
}

message Instance {
    string Name = 1;
    bool Live = 2;
    int32 Port = 4;
}

message ResponseCollection {
    repeated Instance Message = 1; 
}

message Name {
    string Name = 1;
}

message Register {
    string Name = 1;
    string IP = 2;
    int32 Port = 3;
    bool Register = 41;
}

message Comm {
    string Name = 1;
    repeated string Command = 2;
}

message Void {}

service ServerService {
    rpc Start(Name) returns (Response) {}
    rpc Stop(Name) returns (Response) {}
    rpc Restart(Name) returns (Response) {}
    rpc Update(Name) returns (Response) {}
    rpc List(Void) returns (ResponseCollection) {}
    rpc RegisterServer(Register) returns (ResponseCollection) {}
    rpc Reregister(Void) returns (Response) {}
    rpc Command(Comm) returns (Response) {}
    rpc Check(Name) returns (Response) {}
}

运行客户端:

r, _ := c.Stop(ctx, &service.Name{Name: args.Name})
r, _ := c.Restart(ctx, &service.Name{Name: args.Name})
r, _ := c.Update(ctx, &service.Name{Name: args.Name})
r, _ := c.List(ctx, &service.Void{})
r, _ := c.RegisterServer(ctx, &service.Register{Name: args.Name, IP: addr.String(), Port: int32(conf.port), Register: args.Register})
r, _ := c.Reregister(ctx, &service.Void{})
r, _ := c.Command(context.Background(), &service.Comm{Name: args.Name, Command: args.Command})
r, _ := c.Check(context.Background(), &service.Name{Name: args.Name})

服务器端原型:

func (h *ServerHandler) Start(ctx context.Context, name string) *Response
func (h *ServerHandler) Stop(ctx context.Context, name string) *Response
func (h *ServerHandler) Restart(ctx context.Context, name string) *Response
func (h *ServerHandler) Update(ctx context.Context, name string) *Response
func (h *ServerHandler) List(ctx context.Context) *ResponseCollection
func (h *ServerHandler) RegisterServer(ctx context.Context, name string, ip string, port int, register bool) *ResponseCollection
func (h *ServerHandler) Reregister(ctx context.Context) *Response
func (h *ServerHandler) Command(ctx context.Context, name string, command ...string) *Response
func (h *ServerHandler) Check(ctx context.Context, name string) *Response

和结构:

type ResponseCollection struct {
    Message []Instance `json:"message"`
}

type Response struct {
    IsMe     bool   `json:"isMe"`
    Response bool   `json:"response"`
    Message  string `json:"message"`
}

我已经在 table 上苦苦思索了几个小时了。有人看到我没看到的东西吗?

您缺少 *Void 参数:

- func (h *ServerHandler) List(ctx context.Context) *ResponseCollection
+ func (h *ServerHandler) List(ctx context.Context, _ *Void) *ResponseCollection

要调试此类问题,请在您的服务器中嵌入 Unsafe* 接口,而不是 returns 未实现所有方法的向前兼容接口:

type ServerHandler struct {
    UnsafeServerServiceServer
}