mirror of
https://github.com/lorsanstand/HomeOps-Hub.git
synced 2026-06-19 20:05:17 +03:00
refactor: update logs
This commit is contained in:
@@ -2,30 +2,29 @@ package rpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
pb "github.com/lorsanstand/HomeOps-Hub/api/gen/homeops"
|
||||
"github.com/lorsanstand/HomeOps-Hub/internal/agent/domain"
|
||||
"github.com/rs/zerolog"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type Connection struct {
|
||||
hub pb.HubClient
|
||||
conn *grpc.ClientConn
|
||||
log zerolog.Logger
|
||||
}
|
||||
|
||||
func NewConnectAgent(address string) (*Connection, error) {
|
||||
conn, err := grpc.NewClient(address)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed connection hub: %v", err)
|
||||
}
|
||||
func NewConnectAgent(conn *grpc.ClientConn, logger zerolog.Logger) *Connection {
|
||||
logger = logger.With().Str("component", "agent.rpc").Logger()
|
||||
|
||||
client := pb.NewHubClient(conn)
|
||||
|
||||
return &Connection{hub: client, conn: conn}, nil
|
||||
return &Connection{hub: client, conn: conn, log: logger}
|
||||
}
|
||||
|
||||
func (c *Connection) Close() error {
|
||||
c.log.Warn().Msg("connection close")
|
||||
return c.conn.Close()
|
||||
}
|
||||
|
||||
@@ -35,5 +34,6 @@ func (c *Connection) Hub() pb.HubClient {
|
||||
|
||||
func (c *Connection) RegisterAgent(ctx context.Context, RegisterData domain.RegisterAgentData) (domain.RegisterAgentDataResponse, error) {
|
||||
ResponseData, err := c.Hub().RegisterAgent(ctx, new(toAgentRegisterRequest(RegisterData)))
|
||||
c.log.Info().Msg("register agent")
|
||||
return toAgentRegisterDataResponse(ResponseData), err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user