(in *pb.EchoRequest, stream pb.Echo_ServerStreamingEchoServer)
| 77 | } |
| 78 | |
| 79 | func (s *server) ServerStreamingEcho(in *pb.EchoRequest, stream pb.Echo_ServerStreamingEchoServer) error { |
| 80 | fmt.Printf("--- ServerStreamingEcho ---\n") |
| 81 | // Create trailer in defer to record function return time. |
| 82 | defer func() { |
| 83 | trailer := metadata.Pairs("timestamp", time.Now().Format(timestampFormat)) |
| 84 | stream.SetTrailer(trailer) |
| 85 | }() |
| 86 | |
| 87 | // Read metadata from client. |
| 88 | md, ok := metadata.FromIncomingContext(stream.Context()) |
| 89 | if !ok { |
| 90 | return status.Errorf(codes.DataLoss, "ServerStreamingEcho: failed to get metadata") |
| 91 | } |
| 92 | if t, ok := md["timestamp"]; ok { |
| 93 | fmt.Printf("timestamp from metadata:\n") |
| 94 | for i, e := range t { |
| 95 | fmt.Printf(" %d. %s\n", i, e) |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | // Create and send header. |
| 100 | header := metadata.New(map[string]string{"location": "MTV", "timestamp": time.Now().Format(timestampFormat)}) |
| 101 | stream.SendHeader(header) |
| 102 | |
| 103 | fmt.Printf("request received: %v\n", in) |
| 104 | |
| 105 | // Read requests and send responses. |
| 106 | for i := 0; i < streamingCount; i++ { |
| 107 | fmt.Printf("echo message %v\n", in.Message) |
| 108 | err := stream.Send(&pb.EchoResponse{Message: in.Message}) |
| 109 | if err != nil { |
| 110 | return err |
| 111 | } |
| 112 | } |
| 113 | return nil |
| 114 | } |
| 115 | |
| 116 | func (s *server) ClientStreamingEcho(stream pb.Echo_ClientStreamingEchoServer) error { |
| 117 | fmt.Printf("--- ClientStreamingEcho ---\n") |
nothing calls this directly
no test coverage detected