From d593aa528c33e16f472732842dbb141d331cb164 Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Wed, 15 Jan 2025 14:28:36 -0800 Subject: [PATCH 1/6] Require Go 1.23+ --- .github/workflows/go.yml | 2 +- go.mod | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index daacd88..373da79 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -11,7 +11,7 @@ jobs: build: strategy: matrix: - go-version: [1.21.x, 1.22.x] + go-version: [1.23.x] platform: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.platform }} name: "Build ${{ matrix.go-version }} test on ${{ matrix.platform }}" diff --git a/go.mod b/go.mod index 4a63675..c860471 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,6 @@ module github.com/maxmind/mmdbinspect -go 1.21 - -toolchain go1.22.3 +go 1.23 require ( github.com/oschwald/maxminddb-golang v1.13.1 From 998861cca14bc90ad120f549958d9c89ea4359de Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Wed, 15 Jan 2025 14:28:54 -0800 Subject: [PATCH 2/6] Update copyright year --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0f8ca49..db9013c 100644 --- a/README.md +++ b/README.md @@ -473,6 +473,6 @@ Please report bugs by filing an issue with our GitHub issue tracker at [https:// ## Copyright and License -This software is Copyright (c) 2019 - 2024 by MaxMind, Inc. +This software is Copyright (c) 2019 - 2025 by MaxMind, Inc. This is free software, licensed under the [Apache License, Version 2.0](LICENSE-APACHE) or the [MIT License](LICENSE-MIT), at your option. From 587b5c866b2076ad4e61942b872c25dc1809c677 Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Wed, 15 Jan 2025 14:32:22 -0800 Subject: [PATCH 3/6] Improve wording --- pkg/mmdbinspect/mmdbinspect.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/mmdbinspect/mmdbinspect.go b/pkg/mmdbinspect/mmdbinspect.go index 0884b36..4f8089d 100644 --- a/pkg/mmdbinspect/mmdbinspect.go +++ b/pkg/mmdbinspect/mmdbinspect.go @@ -46,9 +46,9 @@ func OpenDB(path string) (*maxminddb.Reader, error) { return db, nil } -// RecordsForNetwork fetches mmdb records inside a given network. If an -// address is provided without a netmask a /32 will be inferred for v4 -// addresses and a /128 will be inferred for v6 addresses. +// RecordsForNetwork fetches mmdb records inside a given network. If an IP +// address is provided without a prefix length, it will be treated as a +// network containing a single address (i.e., /32 for IPv4 and /128 for IPv6). func RecordsForNetwork(reader maxminddb.Reader, includeAliasedNetworks bool, maybeNetwork string) (any, error) { lookupNetwork := maybeNetwork From 46831c7d52118dab553c7485af0b6331ebcf03aa Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Wed, 15 Jan 2025 14:40:31 -0800 Subject: [PATCH 4/6] Upgrade to github.com/oschwald/maxminddb-golang/v2 --- go.mod | 4 ++-- go.sum | 8 ++++---- pkg/mmdbinspect/mmdbinspect.go | 24 +++++++++--------------- pkg/mmdbinspect/mmdbinspect_test.go | 2 +- 4 files changed, 16 insertions(+), 22 deletions(-) diff --git a/go.mod b/go.mod index c860471..d780439 100644 --- a/go.mod +++ b/go.mod @@ -3,13 +3,13 @@ module github.com/maxmind/mmdbinspect go 1.23 require ( - github.com/oschwald/maxminddb-golang v1.13.1 + github.com/oschwald/maxminddb-golang/v2 v2.0.0-beta.2 github.com/stretchr/testify v1.10.0 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/sys v0.21.0 // indirect + golang.org/x/sys v0.29.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 796c043..23003e0 100644 --- a/go.sum +++ b/go.sum @@ -1,13 +1,13 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/oschwald/maxminddb-golang v1.13.1 h1:G3wwjdN9JmIK2o/ermkHM+98oX5fS+k5MbwsmL4MRQE= -github.com/oschwald/maxminddb-golang v1.13.1/go.mod h1:K4pgV9N/GcK694KSTmVSDTODk4IsCNThNdTmnaBZ/F8= +github.com/oschwald/maxminddb-golang/v2 v2.0.0-beta.2 h1:jG+FaCBv3h6GD5F+oenTfe3+0NmX8sCKjni5k3A5Dek= +github.com/oschwald/maxminddb-golang/v2 v2.0.0-beta.2/go.mod h1:rHaQJ5SjfCdL4sqCKa3FhklRcaXga2/qyvmQuA+ZJ6M= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= -golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU= +golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/pkg/mmdbinspect/mmdbinspect.go b/pkg/mmdbinspect/mmdbinspect.go index 4f8089d..426b255 100644 --- a/pkg/mmdbinspect/mmdbinspect.go +++ b/pkg/mmdbinspect/mmdbinspect.go @@ -7,11 +7,11 @@ import ( "errors" "fmt" "io/fs" - "net" + "net/netip" "os" "strings" - "github.com/oschwald/maxminddb-golang" + "github.com/oschwald/maxminddb-golang/v2" ) // RecordForNetwork holds a network and the corresponding record. @@ -60,33 +60,27 @@ func RecordsForNetwork(reader maxminddb.Reader, includeAliasedNetworks bool, may } } - //nolint:forbidigo // preexisting - _, network, err := net.ParseCIDR(lookupNetwork) + network, err := netip.ParsePrefix(lookupNetwork) if err != nil { return nil, fmt.Errorf("%v is not a valid IP address", maybeNetwork) } - var n *maxminddb.Networks + var opts []maxminddb.NetworksOption if includeAliasedNetworks { - n = reader.NetworksWithin(network) - } else { - n = reader.NetworksWithin(network, maxminddb.SkipAliasedNetworks) + opts = append(opts, maxminddb.IncludeAliasedNetworks) } var found []any - for n.Next() { + for res := range reader.NetworksWithin(network, opts...) { var record any - address, err := n.Network(&record) + + err := res.Decode(&record) if err != nil { return nil, fmt.Errorf("could not get next network: %w", err) } - found = append(found, RecordForNetwork{address.String(), record}) - } - - if n.Err() != nil { - return nil, fmt.Errorf("traversing networks: %w", n.Err()) + found = append(found, RecordForNetwork{res.Prefix().String(), record}) } return found, nil diff --git a/pkg/mmdbinspect/mmdbinspect_test.go b/pkg/mmdbinspect/mmdbinspect_test.go index ef43284..f5a1ee6 100644 --- a/pkg/mmdbinspect/mmdbinspect_test.go +++ b/pkg/mmdbinspect/mmdbinspect_test.go @@ -3,7 +3,7 @@ package mmdbinspect import ( "testing" - "github.com/oschwald/maxminddb-golang" + "github.com/oschwald/maxminddb-golang/v2" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) From 2e9157090289cbf7124e13276be7a08e30a6c787 Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Wed, 15 Jan 2025 14:43:18 -0800 Subject: [PATCH 5/6] Bump module to v2 --- CHANGELOG.md | 5 +++++ README.md | 2 +- cmd/mmdbinspect/main.go | 2 +- go.mod | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac2ddf4..874279f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG +## 2.0.0 + +* Upgrade to `github.com/oschwald/maxminddb-golang/v2`. This is a breaking + API change, but should not affect the use of the program. + ## 0.2.0 (2024-01-10) * Don't escape `&`, `<`, and `>` in JSON output diff --git a/README.md b/README.md index db9013c..26f8b7f 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ _We aim always to support the current and penultimate major releases of the Go c The easiest way is via `go install`: ```bash -$ go install github.com/maxmind/mmdbinspect/cmd/mmdbinspect@latest +$ go install github.com/maxmind/mmdbinspect/v2/cmd/mmdbinspect@latest ``` This installs `mmdbinspect` to `$GOPATH/bin/mmdbinspect`. diff --git a/cmd/mmdbinspect/main.go b/cmd/mmdbinspect/main.go index 1619e14..319b2b2 100644 --- a/cmd/mmdbinspect/main.go +++ b/cmd/mmdbinspect/main.go @@ -9,7 +9,7 @@ import ( "os" "strings" - "github.com/maxmind/mmdbinspect/pkg/mmdbinspect" + "github.com/maxmind/mmdbinspect/v2/pkg/mmdbinspect" ) type arrayFlags []string diff --git a/go.mod b/go.mod index d780439..918424d 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/maxmind/mmdbinspect +module github.com/maxmind/mmdbinspect/v2 go 1.23 From 5fc10f33f0b2760378acf015dbb32cd50b5f2352 Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Wed, 15 Jan 2025 14:45:20 -0800 Subject: [PATCH 6/6] Do not convert netip.Prefix to string --- pkg/mmdbinspect/mmdbinspect.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/mmdbinspect/mmdbinspect.go b/pkg/mmdbinspect/mmdbinspect.go index 426b255..a191332 100644 --- a/pkg/mmdbinspect/mmdbinspect.go +++ b/pkg/mmdbinspect/mmdbinspect.go @@ -16,7 +16,7 @@ import ( // RecordForNetwork holds a network and the corresponding record. type RecordForNetwork struct { - Network string + Network netip.Prefix Record any } @@ -80,7 +80,7 @@ func RecordsForNetwork(reader maxminddb.Reader, includeAliasedNetworks bool, may return nil, fmt.Errorf("could not get next network: %w", err) } - found = append(found, RecordForNetwork{res.Prefix().String(), record}) + found = append(found, RecordForNetwork{res.Prefix(), record}) } return found, nil