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/1a581dab-df7e-4f5b-b176-c46be39021ban%40googlegroups.com.

Reply via email to