From 1583f6c1791e901d5f14fdade36f7034c664dc88 Mon Sep 17 00:00:00 2001 From: nohehf <64989428+nohehf@users.noreply.github.com> Date: Tue, 1 Oct 2024 19:06:47 +0200 Subject: [PATCH] chore: fix typo cidr cdir (#7) - replaces occurrences of cdir to cidr --- internal/source/source_alibaba.go | 4 ++-- internal/source/source_digitalocean.go | 4 ++-- internal/source/source_fastly.go | 4 ++-- internal/source/source_gcp.go | 10 ++++----- internal/source/source_ibm.go | 8 ++++---- internal/source/source_linode.go | 4 ++-- internal/source/source_ovh.go | 4 ++-- internal/source/source_scaleway.go | 4 ++-- internal/source/source_tencent.go | 4 ++-- internal/source/source_ucloud.go | 4 ++-- internal/source/utils.go | 4 ++-- internal/tree/tree_test.go | 28 +++++++++++++------------- 12 files changed, 41 insertions(+), 41 deletions(-) diff --git a/internal/source/source_alibaba.go b/internal/source/source_alibaba.go index a418622..d457252 100644 --- a/internal/source/source_alibaba.go +++ b/internal/source/source_alibaba.go @@ -21,8 +21,8 @@ func (a Alibaba) GetIPRanges() []*IPRange { if err != nil { log.Fatal("Failed to load text url to range for Alibaba", err) } - for _, cdir := range alibabaRanges { - network, cat := ParseCIDR(cdir) + for _, cidr := range alibabaRanges { + network, cat := ParseCIDR(cidr) ranges = append(ranges, &IPRange{ Network: network, Cat: cat, diff --git a/internal/source/source_digitalocean.go b/internal/source/source_digitalocean.go index a03e110..94fbcd4 100644 --- a/internal/source/source_digitalocean.go +++ b/internal/source/source_digitalocean.go @@ -30,8 +30,8 @@ func (a Digitalocean) GetIPRanges() []*IPRange { ranges := make([]*IPRange, 0) for _, line := range data { - cdir := line[0] - network, cat := ParseCIDR(cdir) + cidr := line[0] + network, cat := ParseCIDR(cidr) ranges = append(ranges, &IPRange{ Network: network, Cat: cat, diff --git a/internal/source/source_fastly.go b/internal/source/source_fastly.go index 8a3d7de..98c5877 100644 --- a/internal/source/source_fastly.go +++ b/internal/source/source_fastly.go @@ -29,8 +29,8 @@ func (a Fastly) GetIPRanges() []*IPRange { fastlyRanges.Addresses = append(fastlyRanges.Addresses, fastlyRanges.IPv6Addresses...) ranges := make([]*IPRange, 0) - for _, cdir := range fastlyRanges.Addresses { - network, cat := ParseCIDR(cdir) + for _, cidr := range fastlyRanges.Addresses { + network, cat := ParseCIDR(cidr) ranges = append(ranges, &IPRange{ Network: network, Cat: cat, diff --git a/internal/source/source_gcp.go b/internal/source/source_gcp.go index bd4df4d..dd2be42 100644 --- a/internal/source/source_gcp.go +++ b/internal/source/source_gcp.go @@ -38,16 +38,16 @@ func (a Gcp) GetIPRanges() []*IPRange { } for _, prefix := range gcpJSON.Prefixes { - cdir := prefix.IPv4Prefix - if cdir == "" { - cdir = prefix.IPv6Prefix + cidr := prefix.IPv4Prefix + if cidr == "" { + cidr = prefix.IPv6Prefix } - if cdir == "" { + if cidr == "" { log.Fatal("both ipv4 and ipv6 prefixes are empty", errors.New("must have IP")) } - network, cat := ParseCIDR(cdir) + network, cat := ParseCIDR(cidr) ranges = append(ranges, &IPRange{ Network: network, Cat: cat, diff --git a/internal/source/source_ibm.go b/internal/source/source_ibm.go index 210b71a..66399dd 100644 --- a/internal/source/source_ibm.go +++ b/internal/source/source_ibm.go @@ -13,7 +13,7 @@ type Ibm struct{} const ibmFileURL = "https://raw.githubusercontent.com/dprosper/cidr-calculator/main/data/datacenters.json" type cat []*struct { - CdirBlocks []string `json:"cidr_blocks"` + CidrBlocks []string `json:"cidr_blocks"` } type ibmJSON struct { @@ -54,9 +54,9 @@ func (a Ibm) GetIPRanges() []*IPRange { } for _, c := range m { - for _, cdirs := range c { - for _, cdir := range cdirs.CdirBlocks { - network, cat := ParseCIDR(cdir) + for _, cidrs := range c { + for _, cidr := range cidrs.CidrBlocks { + network, cat := ParseCIDR(cidr) if isPrivateNetwork(network) { continue } diff --git a/internal/source/source_linode.go b/internal/source/source_linode.go index 2527109..0d79550 100644 --- a/internal/source/source_linode.go +++ b/internal/source/source_linode.go @@ -21,8 +21,8 @@ func (a Linode) GetIPRanges() []*IPRange { if err != nil { log.Fatal("Failed to load text url to range for Linode", err) } - for _, cdir := range linodeRanges { - network, cat := ParseCIDR(cdir) + for _, cidr := range linodeRanges { + network, cat := ParseCIDR(cidr) ranges = append(ranges, &IPRange{ Network: network, Cat: cat, diff --git a/internal/source/source_ovh.go b/internal/source/source_ovh.go index 395264f..c890abd 100644 --- a/internal/source/source_ovh.go +++ b/internal/source/source_ovh.go @@ -74,8 +74,8 @@ func (a Ovh) GetIPRanges() []*IPRange { log.Info("Using static ovh ip ranges") ranges := make([]*IPRange, 0) - for _, cdir := range ovhRanges { - network, cat := ParseCIDR(cdir) + for _, cidr := range ovhRanges { + network, cat := ParseCIDR(cidr) ranges = append(ranges, &IPRange{ Network: network, Cat: cat, diff --git a/internal/source/source_scaleway.go b/internal/source/source_scaleway.go index b564aa6..3ee120c 100644 --- a/internal/source/source_scaleway.go +++ b/internal/source/source_scaleway.go @@ -34,8 +34,8 @@ func (a Scaleway) GetIPRanges() []*IPRange { log.Info("Using static Scaleway ip ranges") ranges := make([]*IPRange, 0) - for _, cdir := range scalewayRanges { - network, cat := ParseCIDR(cdir) + for _, cidr := range scalewayRanges { + network, cat := ParseCIDR(cidr) ranges = append(ranges, &IPRange{ Network: network, Cat: cat, diff --git a/internal/source/source_tencent.go b/internal/source/source_tencent.go index 79f7e97..26f61b0 100644 --- a/internal/source/source_tencent.go +++ b/internal/source/source_tencent.go @@ -21,8 +21,8 @@ func (a Tencent) GetIPRanges() []*IPRange { if err != nil { log.Fatal("Failed to load text url to range for Tencent", err) } - for _, cdir := range tencentRanges { - network, cat := ParseCIDR(cdir) + for _, cidr := range tencentRanges { + network, cat := ParseCIDR(cidr) ranges = append(ranges, &IPRange{ Network: network, Cat: cat, diff --git a/internal/source/source_ucloud.go b/internal/source/source_ucloud.go index 689aa86..3acd7e3 100644 --- a/internal/source/source_ucloud.go +++ b/internal/source/source_ucloud.go @@ -21,8 +21,8 @@ func (a Ucloud) GetIPRanges() []*IPRange { if err != nil { log.Fatal("Failed to load text url to range for ucloud", err) } - for _, cdir := range ucloudRanges { - network, cat := ParseCIDR(cdir) + for _, cidr := range ucloudRanges { + network, cat := ParseCIDR(cidr) ranges = append(ranges, &IPRange{ Network: network, Cat: cat, diff --git a/internal/source/utils.go b/internal/source/utils.go index 4a81951..dc93a08 100644 --- a/internal/source/utils.go +++ b/internal/source/utils.go @@ -110,14 +110,14 @@ func LoadTextURLToRange(url string) ([]string, error) { func isPrivateNetwork(n *net.IPNet) bool { // Source: https://en.wikipedia.org/wiki/Private_network - for _, cdir := range []string{ + for _, cidr := range []string{ "10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "100.64.0.0/10", "fc00::/7", } { - _, pn, err := net.ParseCIDR(cdir) + _, pn, err := net.ParseCIDR(cidr) if err != nil { panic(err) } diff --git a/internal/tree/tree_test.go b/internal/tree/tree_test.go index eefd38f..a138b36 100644 --- a/internal/tree/tree_test.go +++ b/internal/tree/tree_test.go @@ -16,14 +16,14 @@ func makeTreeHelper() *tree { Root: newNode(), Cat: source.CatIPv4, } - networksCdirs := []string{ + networksCidrs := []string{ "8.8.4.0/24", "3.5.140.0/22", } // build the tree - for _, networkCdir := range networksCdirs { - _, network, err := net.ParseCIDR(networkCdir) + for _, networkCidr := range networksCidrs { + _, network, err := net.ParseCIDR(networkCidr) if err != nil { log.Error("Failed to parse CIDR", err) } @@ -128,9 +128,9 @@ func TestSerializeAndLoad(t *testing.T) { } } -func cdirsToRanges(cdirs []string) []*source.IPRange { +func cidrsToRanges(cidrs []string) []*source.IPRange { ranges := make([]*source.IPRange, 0) - for _, c := range cdirs { + for _, c := range cidrs { net, cat := source.ParseCIDR(c) ranges = append(ranges, &source.IPRange{ Network: net, @@ -140,12 +140,12 @@ func cdirsToRanges(cdirs []string) []*source.IPRange { return ranges } -func rangesToCdirs(ranges []*source.IPRange) []string { - cdirs := make([]string, 0) +func rangesToCidrs(ranges []*source.IPRange) []string { + cidrs := make([]string, 0) for _, r := range ranges { - cdirs = append(cdirs, r.Network.String()) + cidrs = append(cidrs, r.Network.String()) } - return cdirs + return cidrs } func TestOverlapCases(t *testing.T) { @@ -182,18 +182,18 @@ func TestOverlapCases(t *testing.T) { } for _, tt := range tests { - ranges := cdirsToRanges(tt.ranges) + ranges := cidrsToRanges(tt.ranges) tree := NewIPv4Tree() for _, r := range ranges { tree.Add(r) } gotRanges := tree.GetAllRanges() - gotCdirs := rangesToCdirs(gotRanges) - slices.Sort(gotCdirs) + gotCidrs := rangesToCidrs(gotRanges) + slices.Sort(gotCidrs) slices.Sort(tt.expected) - if !slices.Equal(gotCdirs, tt.expected) { - t.Errorf("[%s] Got %+v, Expected: %+v", tt.name, gotCdirs, tt.expected) + if !slices.Equal(gotCidrs, tt.expected) { + t.Errorf("[%s] Got %+v, Expected: %+v", tt.name, gotCidrs, tt.expected) } } }