StartLoopback starts the server on a local address and returns a connection to that address. This function does not add the default DialOptions.
(ctx context.Context, s *grpc.Server, opts ...grpc.DialOption)
| 110 | // StartLoopback starts the server on a local address and returns a connection to that address. |
| 111 | // This function does not add the default DialOptions. |
| 112 | func StartLoopback(ctx context.Context, s *grpc.Server, opts ...grpc.DialOption) (*grpc.ClientConn, error) { |
| 113 | lis := newInProcessListener(ctx) |
| 114 | go s.Serve(lis) |
| 115 | return grpc.Dial( |
| 116 | fmt.Sprintf("passthrough:///%v", lis.Addr()), |
| 117 | append([]grpc.DialOption{ |
| 118 | grpc.WithContextDialer(inProcessDialer(lis)), |
| 119 | grpc.WithTransportCredentials(&inProcessCredentials{}), |
| 120 | }, opts...)...) |
| 121 | } |