MCPcopy
hub / github.com/grpc/grpc-go / newConn

Function newConn

interop/stress/client/main.go:290–323  ·  view source on GitHub ↗
(address string, useTLS, testCA bool, tlsServerName string)

Source from the content-addressed store, hash-verified

288}
289
290func newConn(address string, useTLS, testCA bool, tlsServerName string) (*grpc.ClientConn, error) {
291 var opts []grpc.DialOption
292 if *customCredentialsType != "" {
293 if *customCredentialsType == googleDefaultCredsName {
294 opts = append(opts, grpc.WithCredentialsBundle(google.NewDefaultCredentials()))
295 } else if *customCredentialsType == computeEngineCredsName {
296 opts = append(opts, grpc.WithCredentialsBundle(google.NewComputeEngineCredentials()))
297 } else {
298 logger.Fatalf("Unknown custom credentials: %v", *customCredentialsType)
299 }
300 } else if useTLS {
301 var sn string
302 if tlsServerName != "" {
303 sn = tlsServerName
304 }
305 var creds credentials.TransportCredentials
306 if testCA {
307 var err error
308 if *caFile == "" {
309 *caFile = testdata.Path("x509/server_ca_cert.pem")
310 }
311 creds, err = credentials.NewClientTLSFromFile(*caFile, sn)
312 if err != nil {
313 logger.Fatalf("Failed to create TLS credentials: %v", err)
314 }
315 } else {
316 creds = credentials.NewClientTLSFromCert(nil, sn)
317 }
318 opts = append(opts, grpc.WithTransportCredentials(creds))
319 } else {
320 opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
321 }
322 return grpc.NewClient(address, opts...)
323}
324
325func main() {
326 flag.Parse()

Callers 1

mainFunction · 0.85

Calls 10

WithCredentialsBundleFunction · 0.92
NewDefaultCredentialsFunction · 0.92
PathFunction · 0.92
NewClientTLSFromFileFunction · 0.92
NewClientTLSFromCertFunction · 0.92
WithTransportCredentialsFunction · 0.92
NewCredentialsFunction · 0.92
NewClientFunction · 0.92
FatalfMethod · 0.65

Tested by

no test coverage detected