github.com/weaviate/weaviate@v1.24.6/test/helper/grpc_client.go (about) 1 // _ _ 2 // __ _____ __ ___ ___ __ _| |_ ___ 3 // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \ 4 // \ V V / __/ (_| |\ V /| | (_| | || __/ 5 // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___| 6 // 7 // Copyright © 2016 - 2024 Weaviate B.V. All rights reserved. 8 // 9 // CONTACT: hello@weaviate.io 10 // 11 12 package helper 13 14 import ( 15 "crypto/tls" 16 "fmt" 17 "strings" 18 19 pb "github.com/weaviate/weaviate/grpc/generated/protocol/v1" 20 "google.golang.org/grpc" 21 "google.golang.org/grpc/credentials" 22 "google.golang.org/grpc/credentials/insecure" 23 ) 24 25 func CreateGrpcConnectionClient(host string) (*grpc.ClientConn, error) { 26 var opts []grpc.DialOption 27 opts = append(opts, grpc.WithBlock()) 28 if strings.HasSuffix(host, ":443") { 29 tlsConfig := &tls.Config{ 30 InsecureSkipVerify: true, 31 } 32 opts = append(opts, grpc.WithTransportCredentials(credentials.NewTLS(tlsConfig))) 33 } else { 34 opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials())) 35 } 36 conn, err := grpc.Dial(host, opts...) 37 if err != nil { 38 return nil, fmt.Errorf("failed to dial: %w", err) 39 } 40 return conn, nil 41 } 42 43 func CreateGrpcWeaviateClient(conn *grpc.ClientConn) pb.WeaviateClient { 44 return pb.NewWeaviateClient(conn) 45 }