refactor cluster connection in CLI

This commit is contained in:
Pavel Sviderski
2024-09-11 18:40:06 +10:00
parent c56f81bac2
commit 03c2c0df39
4 changed files with 95 additions and 111 deletions
+5
View File
@@ -8,11 +8,13 @@ import (
"uncloud/internal/machine/api/pb"
)
// Client is a client for the machine API.
type Client struct {
connector Connector
conn *grpc.ClientConn
pb.MachineClient
pb.ClusterClient
}
// Connector is an interface for establishing a connection to the machine API.
@@ -21,6 +23,8 @@ type Connector interface {
Close() error
}
// New creates a new client for the machine API. The connector is used to establish the connection
// either locally or remotely. The client is responsible for closing the connector.
func New(ctx context.Context, connector Connector) (*Client, error) {
c := &Client{
connector: connector,
@@ -32,6 +36,7 @@ func New(ctx context.Context, connector Connector) (*Client, error) {
}
c.MachineClient = pb.NewMachineClient(c.conn)
c.ClusterClient = pb.NewClusterClient(c.conn)
return c, nil
}