forked from cisco-app-networking/networkservicemesh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
endpoint_client.go
51 lines (43 loc) · 1.28 KB
/
endpoint_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
package nsm
import (
"golang.org/x/net/context"
"google.golang.org/grpc"
"github.com/pkg/errors"
"cisco-app-networking.github.io/networkservicemesh/controlplane/api/connection"
"cisco-app-networking.github.io/networkservicemesh/controlplane/api/networkservice"
)
//// Endpoint Connection Client
type endpointClient struct {
client networkservice.NetworkServiceClient
connection *grpc.ClientConn
}
func (c *endpointClient) Request(ctx context.Context, request *networkservice.NetworkServiceRequest) (*connection.Connection, error) {
if c == nil || c.client == nil {
return nil, errors.New("NSE Connection is not initialized...")
}
response, err := c.client.Request(ctx, request)
if err != nil {
return nil, err
}
return response.Clone(), nil
}
func (c *endpointClient) Cleanup() error {
if c == nil || c.client == nil {
return errors.New("NSE Connection is not initialized...")
}
var err error
if c.connection != nil { // Required for testing
err = c.connection.Close()
}
c.connection = nil
c.client = nil
return err
}
func (c *endpointClient) Close(ctx context.Context, conn *connection.Connection) error {
if c.client == nil {
return errors.New("Remote NSM Connection is already cleaned...")
}
_, err := c.client.Close(ctx, conn)
_ = c.Cleanup()
return err
}