Files
HomeOps-Hub/internal/agent/rpc/client.go
T
2026-04-05 16:00:56 +03:00

33 lines
572 B
Go

package rpc
import (
"fmt"
pb "github.com/lorsanstand/HomeOps-Hub/api/gen/homeops"
"google.golang.org/grpc"
)
type Connection struct {
hub pb.HubClient
conn *grpc.ClientConn
}
func NewConnectAgent(address string) (*Connection, error) {
conn, err := grpc.NewClient(address)
if err != nil {
return nil, fmt.Errorf("failed connection hub: %v", err)
}
client := pb.NewHubClient(conn)
return &Connection{hub: client, conn: conn}, nil
}
func (c *Connection) Close() error {
return c.conn.Close()
}
func (c *Connection) Hub() pb.HubClient {
return c.hub
}