Dial dials a gRPC connection to the target.
(ctx context.Context, target string)
| 158 | |
| 159 | // Dial dials a gRPC connection to the target. |
| 160 | func Dial(ctx context.Context, target string) (*grpc.ClientConn, error) { |
| 161 | connMu.Lock() |
| 162 | defer connMu.Unlock() |
| 163 | logger := log.FromContext(ctx).WithField("target", target) |
| 164 | if conn, ok := conns[target]; ok { |
| 165 | logger.Debug("Using existing gRPC connection") |
| 166 | return conn, nil |
| 167 | } |
| 168 | logger.Debug("Connecting to gRPC server...") |
| 169 | conn, err := newClient(ctx, target) |
| 170 | if err != nil { |
| 171 | return nil, err |
| 172 | } |
| 173 | conns[target] = conn |
| 174 | return conn, nil |
| 175 | } |
| 176 | |
| 177 | func newClient(ctx context.Context, target string, opts ...grpc.DialOption) (*grpc.ClientConn, error) { |
| 178 | opts = append(append(rpcclient.DefaultDialOptions(ctx), GetDialOptions()...), opts...) |
no test coverage detected