Skip to content

Commit

Permalink
use switch statements instead of multiple if checks
Browse files Browse the repository at this point in the history
  • Loading branch information
iljarotar committed Nov 7, 2024
1 parent a22c714 commit 24f2973
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions cmd/metal-api/internal/metal/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,14 @@ func mapPortName(port string, sourceOS, targetOS SwitchOSVendor, allLines []int)
return "", fmt.Errorf("unable to get line number from port name, %w", err)
}

if targetOS == SwitchOSVendorCumulus {
return cumulusPortByLineNumber(line, allLines), nil
}
if targetOS == SwitchOSVendorSonic {
switch targetOS {
case SwitchOSVendorSonic:
return sonicPortByLineNumber(line), nil
case SwitchOSVendorCumulus:
return cumulusPortByLineNumber(line, allLines), nil
default:
return "", fmt.Errorf("unknown target switch os %s", targetOS)
}

return "", fmt.Errorf("unknown target switch os %s", targetOS)
}

func getLinesFromPortNames(ports []string, os SwitchOSVendor) ([]int, error) {
Expand All @@ -266,13 +266,15 @@ func getLinesFromPortNames(ports []string, os SwitchOSVendor) ([]int, error) {
}

func portNameToLine(port string, os SwitchOSVendor) (int, error) {
if os == SwitchOSVendorSonic {
switch os {
case SwitchOSVendorSonic:
return sonicPortNameToLine(port)
}
if os == SwitchOSVendorCumulus {
case SwitchOSVendorCumulus:
return cumulusPortNameToLine(port)
default:
return 0, fmt.Errorf("unknown switch os %s", os)
}
return 0, fmt.Errorf("unknown switch os %s", os)

}

func sonicPortNameToLine(port string) (int, error) {
Expand Down

0 comments on commit 24f2973

Please sign in to comment.