From fbf197022f40d08030abe6f0bb34a3c126007fe7 Mon Sep 17 00:00:00 2001 From: Stefan Majer Date: Wed, 13 Nov 2024 12:19:58 +0100 Subject: [PATCH] More consts --- cmd/metal-api/internal/metal/machine.go | 8 ++++---- cmd/metal-api/internal/metal/network.go | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/cmd/metal-api/internal/metal/machine.go b/cmd/metal-api/internal/metal/machine.go index 9a52e202..7f66632a 100644 --- a/cmd/metal-api/internal/metal/machine.go +++ b/cmd/metal-api/internal/metal/machine.go @@ -284,17 +284,17 @@ func validatePorts(ports []int) error { } func validateCIDRs(cidrs []string) error { - af := "" + var af AddressFamily for _, cidr := range cidrs { p, err := netip.ParsePrefix(cidr) if err != nil { return fmt.Errorf("invalid cidr: %w", err) } - var newaf string + var newaf AddressFamily if p.Addr().Is4() { - newaf = "ipv4" + newaf = IPv4AddressFamily } else if p.Addr().Is6() { - newaf = "ipv6" + newaf = IPv6AddressFamily } if af != "" && af != newaf { return fmt.Errorf("mixed address family in one rule is not supported:%v", cidrs) diff --git a/cmd/metal-api/internal/metal/network.go b/cmd/metal-api/internal/metal/network.go index 32a8ae22..0cd638d4 100644 --- a/cmd/metal-api/internal/metal/network.go +++ b/cmd/metal-api/internal/metal/network.go @@ -4,6 +4,7 @@ import ( "net" "net/netip" "strconv" + "strings" "github.com/samber/lo" ) @@ -239,10 +240,10 @@ const ( // ToAddressFamily will convert a string af to a AddressFamily func ToAddressFamily(af string) AddressFamily { - switch af { - case "IPv4", "ipv4": + switch strings.ToLower(af) { + case "ipv4": return IPv4AddressFamily - case "IPv6", "ipv6": + case "ipv6": return IPv6AddressFamily } return IPv4AddressFamily