/
conn.go
49 lines (32 loc) · 1.26 KB
/
conn.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package utils
import (
"flag"
"log"
searchv1 "github.com/AndrewAlizaga/eog_protos/pkg/proto/search"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
var (
tls = flag.Bool("tls", false, "Connection uses TLS if true, else plain TCP")
caFile = flag.String("ca_file", "", "The file containing the CA root cert file")
serverAddr = flag.String("addr", "https://eog-engine.herokuapp.com:50051", "The server address in the format of host:port")
serverHostOverride = flag.String("server_host_override", "x.test.example.com", "The server name used to verify the hostname returned by the TLS handshake")
searchConfigurationConnnection searchv1.SearchServiceClient
)
//var Conn *grpc.ClientConn
func init(){}
func GetSearchConnection() (searchv1.SearchServiceClient, error){
//var err error
var opts []grpc.DialOption
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
if searchConfigurationConnnection == nil {
conn, err := grpc.Dial(*serverAddr, opts...)
if err != nil {
log.Fatalf("fail to dial: %v", err)
return nil, err
}
//defer conn.Close()
searchConfigurationConnnection = searchv1.NewSearchServiceClient(conn)
}
return searchConfigurationConnnection, nil
}