diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 3c2edb0..a431725 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] # We don't test on macOS and windows as the database builds aren't # repeatable there for some reason. As such, tests fail. It'd # probably be worth looking into this at some point. diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 79d7280..ae1c1d8 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -13,7 +13,7 @@ jobs: steps: - uses: actions/setup-go@v5 with: - go-version: 1.22 + go-version: 1.23 - uses: actions/checkout@v4 with: persist-credentials: false diff --git a/README.md b/README.md index 48118a1..cfb18ce 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ post, ## Copyright and License -This software is Copyright (c) 2020-2024 by MaxMind, Inc. +This software is Copyright (c) 2020-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. diff --git a/go.mod b/go.mod index b69c9b8..ef43134 100644 --- a/go.mod +++ b/go.mod @@ -1,19 +1,16 @@ module github.com/maxmind/mmdbwriter -go 1.21 - -toolchain go1.22.3 +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 go4.org/netipx v0.0.0-20231129151722-fdeea329fbba - golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc ) 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 7f20f81..f18041c 100644 --- a/go.sum +++ b/go.sum @@ -1,17 +1,15 @@ 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= go4.org/netipx v0.0.0-20231129151722-fdeea329fbba h1:0b9z3AuHCjxk0x/opv64kcgZLBseWJUpBw5I82+2U4M= go4.org/netipx v0.0.0-20231129151722-fdeea329fbba/go.mod h1:PLyyIXexvUFg3Owu6p/WfdlivPbZJsZdgWZlrGope/Y= -golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc h1:O9NuF4s+E/PvMIy+9IUZB9znFwUIXEWSstNjek6VpVg= -golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc= -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/tree.go b/tree.go index ac10596..c2666f2 100644 --- a/tree.go +++ b/tree.go @@ -11,7 +11,7 @@ import ( "net" "time" - "github.com/oschwald/maxminddb-golang" + "github.com/oschwald/maxminddb-golang/v2" "go4.org/netipx" "github.com/maxmind/mmdbwriter/inserter" @@ -217,28 +217,22 @@ func Load(path string, opts Options) (*Tree, error) { dser := newDeserializer() var networkOpts []maxminddb.NetworksOption - if opts.IPVersion == 6 && !opts.DisableIPv4Aliasing { - networkOpts = append(networkOpts, maxminddb.SkipAliasedNetworks) + if opts.IPVersion == 6 && opts.DisableIPv4Aliasing { + networkOpts = append(networkOpts, maxminddb.IncludeAliasedNetworks) } - networks := db.Networks(networkOpts...) - for networks.Next() { - var network *net.IPNet - + for res := range db.Networks(networkOpts...) { dser.clear() - network, err = networks.Network(dser) + err := res.Decode(dser) if err != nil { return nil, fmt.Errorf("unmarshaling record for network: %w", err) } - err = tree.Insert(network, dser.rv) + err = tree.Insert(netipx.PrefixIPNet(res.Prefix()), dser.rv) if err != nil { return nil, err } } - if err := networks.Err(); err != nil { - return nil, fmt.Errorf("iterating over networks: %w", err) - } return tree, nil } diff --git a/tree_test.go b/tree_test.go index 3fdccf5..d61dfb5 100644 --- a/tree_test.go +++ b/tree_test.go @@ -5,12 +5,13 @@ import ( "fmt" "math/big" "net" + "net/netip" "os" "strings" "testing" "time" - "github.com/oschwald/maxminddb-golang" + "github.com/oschwald/maxminddb-golang/v2" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -737,20 +738,21 @@ func checkMMDB(t *testing.T, buf *bytes.Buffer, gets []testGet, name string) { for _, get := range gets { var v any - //nolint:forbidigo // code predates netip - network, ok, err := reader.LookupNetwork(net.ParseIP(get.ip), &v) + + res := reader.Lookup(netip.MustParseAddr(get.ip)) + err := res.Decode(&v) require.NoError(t, err) assert.Equal( t, get.expectedNetwork, - network.String(), + res.Prefix().String(), "network for %s in database", get.ip, ) if get.expectedLookupValue == nil { - assert.False(t, ok, "%s is not in the database", get.ip) + assert.False(t, res.Found(), "%s is not in the database", get.ip) } else { assert.Equal(t, *get.expectedLookupValue, v, "value for %s in database", get.ip) }