feat: new hub service in hub

This commit is contained in:
2026-04-15 17:55:34 +03:00
parent 0b955bb714
commit 97e9458700
6 changed files with 85 additions and 33 deletions
+18 -1
View File
@@ -2,6 +2,7 @@ package hub_service
import (
"github.com/lorsanstand/HomeOps-Hub/internal/domain"
"github.com/lorsanstand/HomeOps-Hub/internal/hub/utils/hasher"
"github.com/rs/zerolog"
)
@@ -9,4 +10,20 @@ type HubService struct {
log zerolog.Logger
}
func NewHubService(request domain.RegisterAgentRequest)
func NewHubService(logger zerolog.Logger) *HubService {
return &HubService{log: logger}
}
func (h *HubService) RegisterAgent(data domain.RegisterAgentRequest) domain.RegisterAgentResponse {
AgentID := data.AgentId
if data.AgentId == "" {
var err error
AgentID, err = hasher.MakeID(data.Host, data.AgentName)
if err != nil {
h.log.Error().Err(err).Msg("failed create agent id")
AgentID = ""
}
}
return domain.RegisterAgentResponse{AgentID: AgentID, Heartbeat: 5}
}