Hi, If I understand correctly, you are asking about how to access fields in your proto message. There is a getting started with protobufs for Go at https://developers.google.com/protocol-buffers/docs/gotutorial#the_protocol_buffer_api, but for your specific question you should be able to retrieve the user id via the `res.UserId` field on the response message.
Thanks, Eric On Tuesday, August 25, 2020 at 10:21:46 PM UTC-7 [email protected] wrote: > My reference: https://github.com/tinode/chat/blob/master/pbx/model.proto > > I have the following response from a grpc call: > &{id:"4" topic:"fnd" sub:<updated_at:1588240740070 acs:<> public:"{"fn":" > Yogeswari","pn":"Yoges"}" private:"["mhub:e995b6be-b528-4d1b-9e52- > cdcca7ebf4d6"]" user_id:"usr4M22x6F-Fq4" > } > > It is returned by res.GetMessage. > go func() { > // function to receive a bunch of messages > for { > res, err := stream.Recv() > if err == io.EOF { > break > } > if err != nil { > log.Fatalf("Error while receiving: %v", err) > break > } > fmt.Printf("Received: %v\n", res.GetMessage()) > } > close(waitc) > }() > > I need to extract the user_id from the response and I'm able to do it the > following way: > msg := fmt.Sprintf("%v", res.GetMessage()) > s := strings.Index(msg, "user_id:") > if s != -1 { > s += len("user_id:") > e := strings.Index(msg, " > }") > if e != -1 { > fmt.Printf("pos: %s", msg[s:e]) > } > } > > What is the right way to extract the response? How can I assign the result > to a struct (or something else) for easy access in the rest of the code? > > Apology if I'm using some incorrect terms in the question. I'm new to both > golang and grpc. > > Thank you for reading. > > -- You received this message because you are subscribed to the Google Groups "grpc.io" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/31a067b9-89b8-48c4-82fb-956c29e541d1n%40googlegroups.com.
