mirror of
https://github.com/lorsanstand/HomeOps-Hub.git
synced 2026-06-19 16:45:15 +03:00
33 lines
572 B
Go
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
|
|
}
|