-
Notifications
You must be signed in to change notification settings - Fork 0
/
grpc_client.go
55 lines (43 loc) · 1.14 KB
/
grpc_client.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
50
51
52
53
54
55
package qdrant
import (
"context"
qdrant "github.com/Anush008/qclient-go/grpc"
"google.golang.org/grpc"
)
type GrpcClient struct {
conn *grpc.ClientConn
Qdrant qdrant.QdrantClient
Collections qdrant.CollectionsClient
Points qdrant.PointsClient
Snapshots qdrant.SnapshotsClient
}
// connect connect to Service
func NewGrpcClient(ctx context.Context, config *Config) (*GrpcClient, error) {
addr := config.GetAddr()
grpcOptions := config.GrpcOptions
transportCreds := config.GetTransportCreds()
grpcOptions = append(grpcOptions, transportCreds)
conn, err := grpc.DialContext(ctx, addr, grpcOptions...)
if err != nil {
return nil, err
}
return NewGrpcClientFromConn(conn), nil
}
func NewGrpcClientFromConn(conn *grpc.ClientConn) *GrpcClient {
c := &GrpcClient{}
c.conn = conn
c.Qdrant = qdrant.NewQdrantClient(conn)
c.Points = qdrant.NewPointsClient(conn)
c.Collections = qdrant.NewCollectionsClient(conn)
c.Snapshots = qdrant.NewSnapshotsClient(conn)
return c
}
// Close close the connection
func (c *GrpcClient) Close() error {
if c.conn != nil {
err := c.conn.Close()
c.conn = nil
return err
}
return nil
}