Skip to content

Commit 17b5dd8

Browse files
authored
Merge pull request #105 from maxmind/greg/eng-1012-all-githubcom-repos-are-upgraded-to
Upgrade to github.com/oschwald/maxminddb-golang/v2
2 parents 1845c3a + 8e982e9 commit 17b5dd8

File tree

7 files changed

+23
-32
lines changed

7 files changed

+23
-32
lines changed

.github/workflows/go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
build:
1212
strategy:
1313
matrix:
14-
go-version: [1.21.x, 1.22.x]
14+
go-version: [1.23.x]
1515
# We don't test on macOS and windows as the database builds aren't
1616
# repeatable there for some reason. As such, tests fail. It'd
1717
# probably be worth looking into this at some point.

.github/workflows/golangci-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
steps:
1414
- uses: actions/setup-go@v5
1515
with:
16-
go-version: 1.22
16+
go-version: 1.23
1717
- uses: actions/checkout@v4
1818
with:
1919
persist-credentials: false

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ post,
1616

1717
## Copyright and License
1818

19-
This software is Copyright (c) 2020-2024 by MaxMind, Inc.
19+
This software is Copyright (c) 2020-2025 by MaxMind, Inc.
2020

2121
This is free software, licensed under the [Apache License, Version
2222
2.0](LICENSE-APACHE) or the [MIT License](LICENSE-MIT), at your option.

go.mod

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
module github.com/maxmind/mmdbwriter
22

3-
go 1.21
4-
5-
toolchain go1.22.3
3+
go 1.23
64

75
require (
8-
github.com/oschwald/maxminddb-golang v1.13.1
6+
github.com/oschwald/maxminddb-golang/v2 v2.0.0-beta.2
97
github.com/stretchr/testify v1.10.0
108
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba
11-
golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc
129
)
1310

1411
require (
1512
github.com/davecgh/go-spew v1.1.1 // indirect
1613
github.com/pmezard/go-difflib v1.0.0 // indirect
17-
golang.org/x/sys v0.21.0 // indirect
14+
golang.org/x/sys v0.29.0 // indirect
1815
gopkg.in/yaml.v3 v3.0.1 // indirect
1916
)

go.sum

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
22
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3-
github.com/oschwald/maxminddb-golang v1.13.1 h1:G3wwjdN9JmIK2o/ermkHM+98oX5fS+k5MbwsmL4MRQE=
4-
github.com/oschwald/maxminddb-golang v1.13.1/go.mod h1:K4pgV9N/GcK694KSTmVSDTODk4IsCNThNdTmnaBZ/F8=
3+
github.com/oschwald/maxminddb-golang/v2 v2.0.0-beta.2 h1:jG+FaCBv3h6GD5F+oenTfe3+0NmX8sCKjni5k3A5Dek=
4+
github.com/oschwald/maxminddb-golang/v2 v2.0.0-beta.2/go.mod h1:rHaQJ5SjfCdL4sqCKa3FhklRcaXga2/qyvmQuA+ZJ6M=
55
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
66
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
77
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
88
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
99
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba h1:0b9z3AuHCjxk0x/opv64kcgZLBseWJUpBw5I82+2U4M=
1010
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba/go.mod h1:PLyyIXexvUFg3Owu6p/WfdlivPbZJsZdgWZlrGope/Y=
11-
golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc h1:O9NuF4s+E/PvMIy+9IUZB9znFwUIXEWSstNjek6VpVg=
12-
golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
13-
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
14-
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
11+
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
12+
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
1513
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
1614
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
1715
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

tree.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"net"
1212
"time"
1313

14-
"github.com/oschwald/maxminddb-golang"
14+
"github.com/oschwald/maxminddb-golang/v2"
1515
"go4.org/netipx"
1616

1717
"github.com/maxmind/mmdbwriter/inserter"
@@ -217,28 +217,22 @@ func Load(path string, opts Options) (*Tree, error) {
217217
dser := newDeserializer()
218218

219219
var networkOpts []maxminddb.NetworksOption
220-
if opts.IPVersion == 6 && !opts.DisableIPv4Aliasing {
221-
networkOpts = append(networkOpts, maxminddb.SkipAliasedNetworks)
220+
if opts.IPVersion == 6 && opts.DisableIPv4Aliasing {
221+
networkOpts = append(networkOpts, maxminddb.IncludeAliasedNetworks)
222222
}
223223

224-
networks := db.Networks(networkOpts...)
225-
for networks.Next() {
226-
var network *net.IPNet
227-
224+
for res := range db.Networks(networkOpts...) {
228225
dser.clear()
229-
network, err = networks.Network(dser)
226+
err := res.Decode(dser)
230227
if err != nil {
231228
return nil, fmt.Errorf("unmarshaling record for network: %w", err)
232229
}
233230

234-
err = tree.Insert(network, dser.rv)
231+
err = tree.Insert(netipx.PrefixIPNet(res.Prefix()), dser.rv)
235232
if err != nil {
236233
return nil, err
237234
}
238235
}
239-
if err := networks.Err(); err != nil {
240-
return nil, fmt.Errorf("iterating over networks: %w", err)
241-
}
242236
return tree, nil
243237
}
244238

tree_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ import (
55
"fmt"
66
"math/big"
77
"net"
8+
"net/netip"
89
"os"
910
"strings"
1011
"testing"
1112
"time"
1213

13-
"github.com/oschwald/maxminddb-golang"
14+
"github.com/oschwald/maxminddb-golang/v2"
1415
"github.com/stretchr/testify/assert"
1516
"github.com/stretchr/testify/require"
1617

@@ -737,20 +738,21 @@ func checkMMDB(t *testing.T, buf *bytes.Buffer, gets []testGet, name string) {
737738

738739
for _, get := range gets {
739740
var v any
740-
//nolint:forbidigo // code predates netip
741-
network, ok, err := reader.LookupNetwork(net.ParseIP(get.ip), &v)
741+
742+
res := reader.Lookup(netip.MustParseAddr(get.ip))
743+
err := res.Decode(&v)
742744
require.NoError(t, err)
743745

744746
assert.Equal(
745747
t,
746748
get.expectedNetwork,
747-
network.String(),
749+
res.Prefix().String(),
748750
"network for %s in database",
749751
get.ip,
750752
)
751753

752754
if get.expectedLookupValue == nil {
753-
assert.False(t, ok, "%s is not in the database", get.ip)
755+
assert.False(t, res.Found(), "%s is not in the database", get.ip)
754756
} else {
755757
assert.Equal(t, *get.expectedLookupValue, v, "value for %s in database", get.ip)
756758
}

0 commit comments

Comments
 (0)