mirror of
https://github.com/lorsanstand/HomeOps-Hub.git
synced 2026-06-19 20:05:17 +03:00
feat: update conn in hub
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user