-
Notifications
You must be signed in to change notification settings - Fork 101
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
Data inconsistency on decoding #115
Comments
Additional information: If I do the first style (map-based decoding), both "country" and "registered_country" say Russia. However, if I do the second style (struct-based decoding), "country" is Poland, and "registered_country" is Russia. So I think map-style is broken. |
I can't reproduce this: package main
import (
"fmt"
"net"
"github.com/oschwald/maxminddb-golang"
)
func main() {
reader, err := maxminddb.Open("/usr/local/share/GeoIP/GeoLite2-City.mmdb")
if err != nil {
panic(err)
}
var data map[string]any
err = reader.Lookup(net.ParseIP("95.140.157.134"), &data)
if err != nil {
panic(err)
}
fmt.Println(data["country"].(map[string]any)["iso_code"])
var data2 struct {
Country struct {
IsoCode string `maxminddb:"iso_code"`
} `maxminddb:"country"`
}
err = reader.Lookup(net.ParseIP("95.140.157.134"), &data2)
if err != nil {
panic(err)
}
fmt.Println(data2.Country.IsoCode)
} Output:
I am guessing you are ignoring the error from |
I only removed the error handling for the purposes of this issue submission. Here is a full test for me:
This outputs:
Notably, your formulation ( |
As suggested above, your version fails for me. I receive:
This is because the subdivisions are an array, not map. If I ignore the error, I see the behavior you describe. However, I wouldn't expect there to be valid data set by a method that returns an error and I wouldn't consider that a bug. |
This fails, even with the latest tag, v1.11.0? I didn't think to try the latest dev branch, but I will do that tomorrow. Perhaps there is some difference between your branch and the tagged release I am using. All of the returned errors are nil in my code--none of the panics in my example code above are triggered. Could this difference be in the format of the mmdb file I have? |
I have found an issue that I think is the cause of what you are seeing. I'll do a release shortly. |
1.12.0 has been released. That said, I wouldn't recommend decoding to a |
Great, thank you! 1.12.0 is fixed. We do use the struct approach, but upon discovering this discrepancy we were worried which method was correct. |
Hello!
With a relatively recent maxmind country-level DB (let me know if you want my exact copy), we have found at least one IP address that decodes to a different country code based on which de-serialization type is used. This is a bit concerning (we expect it has something to do with registered vs represented countries but we haven't nailed it down).
Here's the difference:
This says Russia.
This says Poland.
What's going on here?
The text was updated successfully, but these errors were encountered: