Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
9 changes: 3 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
)
10 changes: 4 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
18 changes: 6 additions & 12 deletions tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down
12 changes: 7 additions & 5 deletions tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)
}
Expand Down