Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Go rpc错误:代码=未实现描述=未实现rpc方法_Go_Grpc Go - Fatal编程技术网

Go rpc错误:代码=未实现描述=未实现rpc方法

Go rpc错误:代码=未实现描述=未实现rpc方法,go,grpc-go,Go,Grpc Go,我一直在尝试在Go中创建grpc客户端,并按照官方网站上显示的正确说明进行操作。当我启动node.js中编写的grpc服务器时,连接运行良好,但在Go中编译协议缓冲区并使用正确的grpc客户端配置创建客户端接口时,我遇到了一个错误 这是我的identity.pb.go中的内容 type IdentityServiceClient interface { CreateUser(ctx context.Context, in *GoogleIdToken, opts ...grpc.Call

我一直在尝试在Go中创建grpc客户端,并按照官方网站上显示的正确说明进行操作。当我启动node.js中编写的grpc服务器时,连接运行良好,但在Go中编译协议缓冲区并使用正确的grpc客户端配置创建客户端接口时,我遇到了一个错误

这是我的
identity.pb.go中的内容

type IdentityServiceClient interface {
    CreateUser(ctx context.Context, in *GoogleIdToken, opts ...grpc.CallOption) (error, *UserInfo)
}

type simpleServerClient struct {
    connection *grpc.ClientConn
}

func NewSimpleServerClient(connection *grpc.ClientConn) IdentityServiceClient {
    return &simpleServerClient{connection}
}

func (simpleClient *simpleServerClient) CreateUser(ctx context.Context, in *GoogleIdToken, opts ...grpc.CallOption) (error, *UserInfo) {
    out := new(UserInfo)
    err := simpleClient.connection.Invoke(ctx, "/protobuf.IdentityService/CreateUser", in, out, opts...)

    if err != nil {
        return err, nil
    }

    return nil, out
}
这是
identity.proto

syntax="proto3";

package protobuf;

service IdentityService {
    rpc CreateUser (GoogleIdToken) returns (UserInfo) {}
}

message GoogleIdToken {
    string token = 1;
}

message UserInfo {
    string name = 1;
    string email = 2;
    message Profile {
        string imageUrl = 1;
        string lastUpdated = 2;
    };
    Profile profile = 3;
    string token = 4;
}

这是我的
main.go

import pb "github.com/Duncanian/iam-gateway/server/protobuf"

func grpcConnection() {
    conn, err := grpc.Dial("localhost:50051", grpc.WithInsecure())
    if err != nil {
        log.Fatalf("Failed to start gRPC connection: %v", err)
    }

    defer conn.Close()

    client := pb.NewSimpleServerClient(conn)

    err, _ = client.CreateUser(context.Background(), &pb.GoogleIdToken{Token: "tevgvybububvvg"})
    if err != nil {
        log.Fatalf("Failed to create user: %v", err)
    }
    log.Println("Created user!")
}
我希望通过传递正确的GoogleAuth令牌的输出来获得正确的用户详细信息

name: user,
email: user.email@user.com,
profile: {
   imageUrl: myimageUrl,
   lastUpdated: mylastUpdatedTime,
},
token,
但是得到

rpc error: code = Unimplemented desc = RPC method not implemented /protobuf.IdentityService/CreateUser
以下是我的github回购协议: &

该错误表示未在服务器端注册
/protobuf.IdentityService/CreateUser
方法。我在你链接的服务器代码中没有看到任何服务注册代码。请查看node.js指南。

使用grpc的GUI尝试将您的protos发送到两台服务器,并检查即将出现的错误/正确的端点

在我的例子中,java proto有一个添加到端点的包。
Had
package com.example.grpc
而不是

选项java_package=“com.example.grpc”

我也有同样的问题

以下是我的解决方案: 编译
.proto
后,我创建了两个文件:
client.go
server.go

type IdentityServiceClient interface {
    CreateUser(ctx context.Context, in *GoogleIdToken, opts ...grpc.CallOption) (error, *UserInfo)
}

type simpleServerClient struct {
    connection *grpc.ClientConn
}

func NewSimpleServerClient(connection *grpc.ClientConn) IdentityServiceClient {
    return &simpleServerClient{connection}
}

func (simpleClient *simpleServerClient) CreateUser(ctx context.Context, in *GoogleIdToken, opts ...grpc.CallOption) (error, *UserInfo) {
    out := new(UserInfo)
    err := simpleClient.connection.Invoke(ctx, "/protobuf.IdentityService/CreateUser", in, out, opts...)

    if err != nil {
        return err, nil
    }

    return nil, out
}
client.go
中,我实现了我的方法(根据protobuffers的rpc),并拥有一个
main
函数

server.go
中,我定义了一个服务器结构
server
,其中有一个字段:
Unimplemented*ServiceName*server
。之后,我还实现了上面提到的方法,但这些方法的接收方类型是:
func(s*server)Foo(ctx context.context,*other params*)


这对我很有用,希望它能帮助你

我已经在node.js服务器中注册了该服务。我还不太熟悉node.js的工作原理。我建议您使用命令行工具(如)检查服务是否确实已注册,因为错误表明它未注册。