(stream pb.Echo_ClientStreamingEchoServer)
| 114 | } |
| 115 | |
| 116 | func (s *server) ClientStreamingEcho(stream pb.Echo_ClientStreamingEchoServer) error { |
| 117 | fmt.Printf("--- ClientStreamingEcho ---\n") |
| 118 | // Create trailer in defer to record function return time. |
| 119 | defer func() { |
| 120 | trailer := metadata.Pairs("timestamp", time.Now().Format(timestampFormat)) |
| 121 | stream.SetTrailer(trailer) |
| 122 | }() |
| 123 | |
| 124 | // Read metadata from client. |
| 125 | md, ok := metadata.FromIncomingContext(stream.Context()) |
| 126 | if !ok { |
| 127 | return status.Errorf(codes.DataLoss, "ClientStreamingEcho: failed to get metadata") |
| 128 | } |
| 129 | if t, ok := md["timestamp"]; ok { |
| 130 | fmt.Printf("timestamp from metadata:\n") |
| 131 | for i, e := range t { |
| 132 | fmt.Printf(" %d. %s\n", i, e) |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | // Create and send header. |
| 137 | header := metadata.New(map[string]string{"location": "MTV", "timestamp": time.Now().Format(timestampFormat)}) |
| 138 | stream.SendHeader(header) |
| 139 | |
| 140 | // Read requests and send responses. |
| 141 | var message string |
| 142 | for { |
| 143 | in, err := stream.Recv() |
| 144 | if err == io.EOF { |
| 145 | fmt.Printf("echo last received message\n") |
| 146 | return stream.SendAndClose(&pb.EchoResponse{Message: message}) |
| 147 | } |
| 148 | message = in.Message |
| 149 | fmt.Printf("request received: %v, building echo\n", in) |
| 150 | if err != nil { |
| 151 | return err |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | func (s *server) BidirectionalStreamingEcho(stream pb.Echo_BidirectionalStreamingEchoServer) error { |
| 157 | fmt.Printf("--- BidirectionalStreamingEcho ---\n") |
nothing calls this directly
no test coverage detected