From 56963382bfba2179dc7412213ab9066eea1150da Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Mon, 5 Aug 2024 13:40:50 -0700 Subject: [PATCH] Inline function It used to be more complex before we switched to net/netip. It no longer adds anything. --- convert/convert.go | 15 ++++----------- convert/convert_test.go | 3 ++- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/convert/convert.go b/convert/convert.go index 51697d4..8893a92 100644 --- a/convert/convert.go +++ b/convert/convert.go @@ -199,11 +199,12 @@ func convert( return fmt.Errorf("reading CSV: %w", err) } - p, err := makePrefix(record[0]) + prefix, err := netip.ParsePrefix(record[0]) if err != nil { - return err + return fmt.Errorf("parsing network (%s): %w", record[0], err) } - err = writer.Write(makeLine(p, record[1:])) + + err = writer.Write(makeLine(prefix, record[1:])) if err != nil { return fmt.Errorf("writing CSV: %w", err) } @@ -217,11 +218,3 @@ func convert( return nil } - -func makePrefix(network string) (netip.Prefix, error) { - prefix, err := netip.ParsePrefix(network) - if err != nil { - return prefix, fmt.Errorf("parsing network (%s): %w", network, err) - } - return prefix, nil -} diff --git a/convert/convert_test.go b/convert/convert_test.go index b8c0522..08368c7 100644 --- a/convert/convert_test.go +++ b/convert/convert_test.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "io" + "net/netip" "os" "strings" "testing" @@ -127,7 +128,7 @@ func checkLine( network string, expected []string, ) { - p, err := makePrefix(network) + p, err := netip.ParsePrefix(network) if err != nil { t.Fatal(err) }