mirror of
https://github.com/lorsanstand/HomeOps-Hub.git
synced 2026-06-19 20:05:17 +03:00
refactor: move domain structure and mapper
This commit is contained in:
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
pb "github.com/lorsanstand/HomeOps-Hub/api/gen/homeops"
|
||||
"github.com/lorsanstand/HomeOps-Hub/internal/agent/domain"
|
||||
"github.com/lorsanstand/HomeOps-Hub/internal/domain"
|
||||
"github.com/rs/zerolog"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
@@ -32,8 +32,8 @@ func (c *Connection) Hub() pb.HubClient {
|
||||
return c.hub
|
||||
}
|
||||
|
||||
func (c *Connection) RegisterAgent(ctx context.Context, RegisterData domain.RegisterAgentData) (domain.RegisterAgentDataResponse, error) {
|
||||
ResponseData, err := c.Hub().RegisterAgent(ctx, new(toAgentRegisterRequest(RegisterData)))
|
||||
func (c *Connection) RegisterAgent(ctx context.Context, RegisterData domain.RegisterAgentRequest) (domain.RegisterAgentResponse, error) {
|
||||
ResponseData, err := c.Hub().RegisterAgent(ctx, new(domain.ToGRPCAgentRequest(RegisterData)))
|
||||
c.log.Info().Msg("register agent")
|
||||
return toAgentRegisterDataResponse(ResponseData), err
|
||||
return domain.ToDomainAgentResponse(ResponseData), err
|
||||
}
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
package rpc
|
||||
|
||||
import (
|
||||
pb "github.com/lorsanstand/HomeOps-Hub/api/gen/homeops"
|
||||
"github.com/lorsanstand/HomeOps-Hub/internal/agent/domain"
|
||||
)
|
||||
|
||||
func toAgentRegisterRequest(request domain.RegisterAgentData) pb.RegisterAgentRequest {
|
||||
return pb.RegisterAgentRequest{
|
||||
AgentId: request.AgentId,
|
||||
AgentName: request.AgentName,
|
||||
Host: &pb.HostInfo{
|
||||
Hostname: request.Host.Hostname,
|
||||
Arch: request.Host.Arch,
|
||||
System: request.Host.System,
|
||||
},
|
||||
Version: request.AgentVersion,
|
||||
Capability: toGRPCCapability(request.Capabilities),
|
||||
}
|
||||
}
|
||||
|
||||
func toGRPCCapability(caps []domain.Capability) []*pb.Capability {
|
||||
var capability []*pb.Capability
|
||||
for _, capi := range caps {
|
||||
capability = append(capability, &pb.Capability{
|
||||
Name: capi.Name,
|
||||
Available: capi.Available,
|
||||
Version: capi.Version,
|
||||
Reason: capi.Reason,
|
||||
})
|
||||
}
|
||||
return capability
|
||||
}
|
||||
|
||||
func toAgentRegisterDataResponse(response *pb.RegisterAgentResponse) domain.RegisterAgentDataResponse {
|
||||
if response == nil {
|
||||
return domain.RegisterAgentDataResponse{}
|
||||
}
|
||||
|
||||
return domain.RegisterAgentDataResponse{
|
||||
AgentID: response.AgentId,
|
||||
Heartbeat: int(response.HeartbeatIntervalSecond),
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,9 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/lorsanstand/HomeOps-Hub/internal/agent/domain"
|
||||
"github.com/lorsanstand/HomeOps-Hub/internal/agent/utils/config_yaml"
|
||||
"github.com/lorsanstand/HomeOps-Hub/internal/agent/utils/settings"
|
||||
"github.com/lorsanstand/HomeOps-Hub/internal/domain"
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
@@ -15,7 +15,7 @@ type Collector interface {
|
||||
}
|
||||
|
||||
type HubConnection interface {
|
||||
RegisterAgent(ctx context.Context, RegisterData domain.RegisterAgentData) (domain.RegisterAgentDataResponse, error)
|
||||
RegisterAgent(ctx context.Context, RegisterData domain.RegisterAgentRequest) (domain.RegisterAgentResponse, error)
|
||||
}
|
||||
|
||||
type AgentService struct {
|
||||
@@ -43,7 +43,7 @@ func (a *AgentService) RegisterAgentConn(ctx context.Context) {
|
||||
info, caps := a.collect.GatherInfoSystem()
|
||||
AgentID := a.settings.AgentID
|
||||
AgentName := a.cfg.AppName
|
||||
AgentData := domain.RegisterAgentData{AgentId: AgentID, AgentName: AgentName, Host: info, Capabilities: caps}
|
||||
AgentData := domain.RegisterAgentRequest{AgentId: AgentID, AgentName: AgentName, Host: info, Capabilities: caps}
|
||||
|
||||
data, err := a.conn.RegisterAgent(ctx, AgentData)
|
||||
if err != nil {
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"os"
|
||||
"runtime"
|
||||
|
||||
"github.com/lorsanstand/HomeOps-Hub/internal/agent/domain"
|
||||
"github.com/lorsanstand/HomeOps-Hub/internal/domain"
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package docker_service
|
||||
|
||||
import "github.com/lorsanstand/HomeOps-Hub/internal/agent/domain"
|
||||
import (
|
||||
"github.com/lorsanstand/HomeOps-Hub/internal/domain"
|
||||
)
|
||||
|
||||
type BadDocker struct {
|
||||
reason string
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/lorsanstand/HomeOps-Hub/internal/agent/domain"
|
||||
"github.com/lorsanstand/HomeOps-Hub/internal/domain"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user