86 lines
2 KiB
Go
86 lines
2 KiB
Go
/*
|
|
* ============================================================================
|
|
* Projekt.....: rs2322tcp
|
|
* Datei.......: internal/client/virtual_port_validation.go
|
|
* Copyright (C) 2026 Dieter Lang
|
|
*
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
*
|
|
* Beschreibung:
|
|
* Vergleich der in client.json definierten virtuellen Ports mit den
|
|
* tatsächlich vorhandenen virtuellen Schnittstellen.
|
|
* ============================================================================
|
|
*/
|
|
package client
|
|
|
|
import "sort"
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// Virtual port validation
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// VirtualPortValidationResult contains the differences between configured
|
|
// and locally available virtual ports.
|
|
type VirtualPortValidationResult struct {
|
|
Missing []string
|
|
Extra []string
|
|
}
|
|
|
|
// compareVirtualPorts compares the configured virtual ports with the
|
|
// locally available virtual ports.
|
|
//
|
|
// Missing contains ports configured in client.json that are not available
|
|
// locally.
|
|
//
|
|
// Extra contains locally available ports that are not configured in
|
|
// client.json.
|
|
//
|
|
// The order of both input lists is irrelevant.
|
|
func compareVirtualPorts(
|
|
configured []string,
|
|
available []string,
|
|
) VirtualPortValidationResult {
|
|
configuredSet := make(map[string]struct{}, len(configured))
|
|
|
|
for _, port := range configured {
|
|
configuredSet[port] = struct{}{}
|
|
}
|
|
|
|
availableSet := make(map[string]struct{}, len(available))
|
|
|
|
for _, port := range available {
|
|
availableSet[port] = struct{}{}
|
|
}
|
|
|
|
result := VirtualPortValidationResult{
|
|
Missing: make([]string, 0),
|
|
Extra: make([]string, 0),
|
|
}
|
|
|
|
for port := range configuredSet {
|
|
if _, ok := availableSet[port]; ok {
|
|
continue
|
|
}
|
|
|
|
result.Missing = append(
|
|
result.Missing,
|
|
port,
|
|
)
|
|
}
|
|
|
|
for port := range availableSet {
|
|
if _, ok := configuredSet[port]; ok {
|
|
continue
|
|
}
|
|
|
|
result.Extra = append(
|
|
result.Extra,
|
|
port,
|
|
)
|
|
}
|
|
|
|
sort.Strings(result.Missing)
|
|
sort.Strings(result.Extra)
|
|
|
|
return result
|
|
}
|