Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to implement GetServiceInfo method

I am creating a grpc service in go, I set up my grpc as follows

func setupGrpc() {
    lis, err := net.Listen("tcp", ":9000")
    if err != nil {
        log.Fatalf("failed to listen: %v", err)
    }

    s := followerservice.UserServer{}

    grpcServer := grpc.NewServer()
    gen.RegisterUserServiceServer(grpcServer, &s)

    // for ease of cli dev
    reflection.Register(s) // this doesn't work!

    if err := grpcServer.Serve(lis); err != nil {
        log.Fatalf("failed to serve: %s", err)
    }
}

My UserServer looks like this

type UserServer struct {
    gen.UnimplementedUserServiceServer
}

func (s *UserServer) Create(ctx context.Context, in *gen.CreateUserRequest)(*gen.CreateUserResponse, error) {
    log.Printf("Receive message body from client: %s", in.Email)
    return &gen.CreateUserResponse{Id: "new id!"}, nil
}

At the line marked in func setupGrpc() I get a compile time error followerservice.UserServer does not implement reflection.GRPCServer (missing GetServiceInfo method) but I can’t find out how to implement it, I’ve been googling for hours now. It feels like protoc could generate this for me, but I’m kinda confused.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You have to reflection.Register the *grpc.Server that you got from the grpc.NewServer() constructor, not your own implementation.

    grpcServer := grpc.NewServer()
    gen.RegisterUserServiceServer(grpcServer, &s)

    reflection.Register(grpcServer)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading