-
Notifications
You must be signed in to change notification settings - Fork 23
go: upgrade to maxminddb-golang/v2 #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,12 @@ | ||
| package lib | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "errors" | ||
| "fmt" | ||
| "net" | ||
| "net/netip" | ||
| "reflect" | ||
|
|
||
| "github.com/oschwald/maxminddb-golang" | ||
| "github.com/oschwald/maxminddb-golang/v2" | ||
| "github.com/spf13/pflag" | ||
| ) | ||
|
|
||
|
|
@@ -51,33 +50,32 @@ func doDiff( | |
| newDbStr string, | ||
| oldDb *maxminddb.Reader, | ||
| oldDbStr string, | ||
| ) (map[interface{}]*net.IPNet, map[interface{}]cmdDiffRecord, error) { | ||
| modifiedSubnets := map[interface{}]*net.IPNet{} | ||
| modifiedRecords := map[interface{}]cmdDiffRecord{} | ||
| networksA := newDb.Networks(maxminddb.SkipAliasedNetworks) | ||
| for networksA.Next() { | ||
| ) (map[netip.Prefix]netip.Prefix, map[netip.Prefix]cmdDiffRecord, error) { | ||
| modifiedSubnets := map[netip.Prefix]netip.Prefix{} | ||
| modifiedRecords := map[netip.Prefix]cmdDiffRecord{} | ||
| for result := range newDb.Networks() { | ||
| var recordA interface{} | ||
| var recordB interface{} | ||
|
|
||
| subnetA, err := networksA.Network(&recordA) | ||
| if err != nil { | ||
| if err := result.Decode(&recordA); err != nil { | ||
| return nil, nil, fmt.Errorf( | ||
| "failed to get record for subnet from %v: %w", | ||
| newDbStr, err, | ||
| ) | ||
| } | ||
| subnetA := result.Prefix() | ||
|
|
||
| subnetB, _, err := oldDb.LookupNetwork(subnetA.IP, &recordB) | ||
| if err != nil { | ||
| lookupResult := oldDb.Lookup(subnetA.Addr()) | ||
| if err := lookupResult.Decode(&recordB); err != nil { | ||
| return nil, nil, fmt.Errorf( | ||
| "failed to get record for IP %v from %v: %w", | ||
| subnetA.IP, oldDbStr, err, | ||
| subnetA.Addr(), oldDbStr, err, | ||
| ) | ||
| } | ||
| subnetB := lookupResult.Prefix() | ||
|
|
||
| // unequal subnets? | ||
| if bytes.Compare(subnetA.IP, subnetB.IP) != 0 || | ||
| bytes.Compare(subnetA.Mask, subnetB.Mask) != 0 { | ||
| if subnetA != subnetB { | ||
| modifiedSubnets[subnetA] = subnetB | ||
| continue | ||
| } | ||
|
|
@@ -90,12 +88,6 @@ func doDiff( | |
| } | ||
| } | ||
| } | ||
| if networksA.Err() != nil { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No sure if you need similar handling still
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not needed anymore, the error is now embedded in the result struct. If there is an error it will raise at decode time. |
||
| return nil, nil, fmt.Errorf( | ||
| "failed traversing networks of %v: %w", | ||
| newDbStr, networksA.Err(), | ||
| ) | ||
| } | ||
|
|
||
| return modifiedSubnets, modifiedRecords, nil | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.