Need help with go micro

3 days ago by ostheperson · Flag

Hello Asim, saw you’re a long-time contributor to go-micro repo. I’ve been trying to get it to work but I’m facing an issue. didn’t want to make a whole issue until I’ve confirmed I’m doing it right.

Basically, I’m calling a micro service via an api gateway and get an error when the response contains the google.protobuf.Timestamp type.

{“id”:“go.micro.client.codec”,“code”:500,“detail”:“json: cannot unmarshal object into Go value of type string”,“status”:“Internal Server Error”}

minimum code to reproduce

gateway

...
type Gateway struct {
	helloworldclient pb.HelloworldService
}

func (g *Gateway) Hello(w http.ResponseWriter, r *http.Request) {
	rsp, err := g.helloworldclient.Call(r.Context(), &pb.Request{})
	if err != nil {
                // error point
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}
}

func main() {
	svc := micro.NewService(
		micro.Name("gateway"),
	)
	gw := Gateway{
		helloworldclient: pb.NewHelloworldService("helloworld", svc.Client()),
	}
	http.HandleFunc("/", gw.Hello)
	http.ListenAndServe(":5000", nil)
}

helloworld service

type Handler struct{}

func (h *Handler) Call(ctx context.Context, req *pb.Request, rsp *pb.Response) error {
	rsp.Msg = "called"
	rsp.Timestamp = timestamppb.New(time.Now()) // works fine without this line
	return nil
}

func main() {
	service := micro.New("helloworld")
	service.Init()
	pb.RegisterHelloworldHandler(service.Server(), new(Handler))
	service.Run()
}
...
import "google/protobuf/timestamp.proto";

service Helloworld {
	rpc Call(Request) returns (Response) {}
}

message Request {
	string name = 1;
}

message Response {
	string msg = 1;
	google.protobuf.Timestamp timestamp = 2;
}

Comments

Login to add a comment

2 days ago by Asim
I think probably best to file a github issue!
← Back to posts