mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 11:03:34 +00:00
--------- Co-authored-by: Pasha Sviderski <me@psviderski.name> Co-authored-by: Anton Ovchinnikov <anton@tonyo.info>
35 lines
756 B
Go
35 lines
756 B
Go
package connector
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/netip"
|
|
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/credentials/insecure"
|
|
)
|
|
|
|
// TCPConnector establishes a connection to the machine API through a direct TCP connection to an API endpoint.
|
|
type TCPConnector struct {
|
|
apiAddr netip.AddrPort
|
|
}
|
|
|
|
func NewTCPConnector(apiAddr netip.AddrPort) *TCPConnector {
|
|
return &TCPConnector{apiAddr: apiAddr}
|
|
}
|
|
|
|
func (c *TCPConnector) Connect(_ context.Context) (*grpc.ClientConn, error) {
|
|
conn, err := grpc.NewClient(
|
|
c.apiAddr.String(),
|
|
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
|
)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("create machine API client: %w", err)
|
|
}
|
|
return conn, nil
|
|
}
|
|
|
|
func (c *TCPConnector) Close() error {
|
|
return nil
|
|
}
|