Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ChenMoGe2 opened this issue Jul 8, 2021 · 0 comments
Open

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

ChenMoGe2 opened this issue Jul 8, 2021 · 0 comments

Comments

@ChenMoGe2
Copy link

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

完整报错信息

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)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant