Skip to content

panic: *helloword.HelloRequest is not a proto.Marshaler #3

@ChenMoGe2

Description

@ChenMoGe2

使用该项目示例时,客户端发送消息会报如标题错误

完整报错信息

panic: *goout.HelloRequest is not a proto.Marshaler

goroutine 1 [running]:
main.main()
 D:/GoLand 2021.1.1/workspace/background/gnetserver/pkg/grpc/sayhello/clinet/sayhelloclient.go:27 +0x1fe

proto文件生成命令

protoc --go_out=plugins=rpcx:. *.proto

proto文件

syntax = "proto3";

option go_package = "sayhello";

package helloworld;

// The greeting service definition.
service Greeter {
  // Sends a greeting
  rpc SayHello (HelloRequest) returns (HelloReply) {}
}

// The request message containing the user's name.
message HelloRequest {
  string name = 1;
}

// The response message containing the greetings
message HelloReply {
  string message = 1;
}

服务端

package main

import (
	helloworld "background/gnetserver/pkg/grpc/sayhello/goout"
	"context"
	"fmt"
	"github.com/smallnest/rpcx/server"
)

func main() {
	s := server.NewServer()
	s.RegisterName("Greeter", new(GreeterImpl), "")
	err := s.Serve("tcp", "127.0.0.1:8972")
	if err != nil {
		panic(err)
	}
}

type GreeterImpl struct{}

func (s *GreeterImpl) SayHello(ctx context.Context, args *helloworld.HelloRequest, reply *helloworld.HelloReply) (err error) {
	*reply = helloworld.HelloReply{
		Message: fmt.Sprintf("hello %s!", args.Name),
	}
	return nil
}

客户端

package main

import (
	helloworld "background/gnetserver/pkg/grpc/sayhello/goout"
	"context"
	"fmt"
)

func main() {
	xclient,_ := helloworld.NewXClientForGreeter("127.0.0.1:8972")
	client := helloworld.NewGreeterClient(xclient)

	args := &helloworld.HelloRequest{
		Name: "rpcx",
	}

	reply, err := client.SayHello(context.Background(), args)
	if err != nil {
		panic(err)
	}

	fmt.Println("reply: ", reply.Message)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions