Skip to content

Commit

Permalink
fix duplicate ips
Browse files Browse the repository at this point in the history
  • Loading branch information
coddmeistr committed Jan 17, 2025
1 parent f7e3798 commit f13c02f
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions pkg/billing/cron_send_services_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func (s *BillingServiceServer) CollectSystemReport(ctx context.Context, log *zap
ClientID: clID,
OrderID: srv.OrderID,
ProductName: srv.Name,
IP: strings.Trim(strings.Join([]string{srv.DedicatedIP, srv.Domain, srv.ServerIP}, " "), " "),
IP: strings.Trim(strings.Join(removeDuplicates([]string{srv.DedicatedIP, srv.Domain, srv.ServerIP}), " "), " "),
DateCreate: srv.RegDate,
Status: srv.Status,
Price: strings.Trim(strings.Join([]string{fp, rp}, " "), " "),
Expand All @@ -278,13 +278,12 @@ func (s *BillingServiceServer) CollectSystemReport(ctx context.Context, log *zap
}
}
}
var ips string
ips := make([]string, 0)
if srv.GetState() != nil && srv.GetState().GetInterfaces() != nil {
for _, inter := range srv.GetState().GetInterfaces() {
ips += inter.GetData()["host"] + " "
ips = append(ips, inter.GetData()["host"])
}
}
ips = strings.Trim(ips, " ")
reportsServices = append(reportsServices, ServiceReport{
WhmcsID: -1,
ClientID: clID,
Expand All @@ -293,7 +292,7 @@ func (s *BillingServiceServer) CollectSystemReport(ctx context.Context, log *zap
DateCreate: time.Unix(srv.Created, 0).Format(time.DateOnly),
Status: srv.Status.String(),
Price: price,
IP: ips,
IP: strings.Trim(strings.Join(removeDuplicates(ips), " "), " "),
})
}
}
Expand Down Expand Up @@ -376,3 +375,15 @@ func writeToFile(log *zap.Logger, prefix string, content string) error {
}
return nil
}

func removeDuplicates(strings []string) []string {
unique := make(map[string]bool)
result := make([]string, 0)
for _, str := range strings {
if _, exists := unique[str]; !exists {
unique[str] = true
result = append(result, str)
}
}
return result
}

0 comments on commit f13c02f

Please sign in to comment.