(ctx context.Context, in *pb.EchoRequest)
| 48 | } |
| 49 | |
| 50 | func (s *server) UnaryEcho(ctx context.Context, in *pb.EchoRequest) (*pb.EchoResponse, error) { |
| 51 | fmt.Printf("--- UnaryEcho ---\n") |
| 52 | // Create trailer in defer to record function return time. |
| 53 | defer func() { |
| 54 | trailer := metadata.Pairs("timestamp", time.Now().Format(timestampFormat)) |
| 55 | grpc.SetTrailer(ctx, trailer) |
| 56 | }() |
| 57 | |
| 58 | // Read metadata from client. |
| 59 | md, ok := metadata.FromIncomingContext(ctx) |
| 60 | if !ok { |
| 61 | return nil, status.Errorf(codes.DataLoss, "UnaryEcho: failed to get metadata") |
| 62 | } |
| 63 | if t, ok := md["timestamp"]; ok { |
| 64 | fmt.Printf("timestamp from metadata:\n") |
| 65 | for i, e := range t { |
| 66 | fmt.Printf(" %d. %s\n", i, e) |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | // Create and send header. |
| 71 | header := metadata.New(map[string]string{"location": "MTV", "timestamp": time.Now().Format(timestampFormat)}) |
| 72 | grpc.SendHeader(ctx, header) |
| 73 | |
| 74 | fmt.Printf("request received: %v, sending echo\n", in) |
| 75 | |
| 76 | return &pb.EchoResponse{Message: in.Message}, nil |
| 77 | } |
| 78 | |
| 79 | func (s *server) ServerStreamingEcho(in *pb.EchoRequest, stream pb.Echo_ServerStreamingEchoServer) error { |
| 80 | fmt.Printf("--- ServerStreamingEcho ---\n") |
nothing calls this directly
no test coverage detected