-
Notifications
You must be signed in to change notification settings - Fork 32
/
client.go
35 lines (30 loc) · 901 Bytes
/
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
// Package grpc provides the basic interfaces to build a gRPC+Protobuf flows client & server
package grpc
import (
"github.com/netobserv/netobserv-ebpf-agent/pkg/pbflow"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
// ClientConnection wraps a gRPC+protobuf connection
type ClientConnection struct {
client pbflow.CollectorClient
conn *grpc.ClientConn
}
func ConnectClient(address string) (*ClientConnection, error) {
// TODO: allow configuring some options (keepalive, backoff...)
conn, err := grpc.Dial(address,
grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return nil, err
}
return &ClientConnection{
client: pbflow.NewCollectorClient(conn),
conn: conn,
}, nil
}
func (cp *ClientConnection) Client() pbflow.CollectorClient {
return cp.client
}
func (cp *ClientConnection) Close() error {
return cp.conn.Close()
}