oschwald / maxminddb-golang

MaxMind DB Reader for Go
ISC License
615 stars 101 forks source link

[question] why isn't there a type for the result of the scan? #112

Closed wsw70 closed 1 year ago

wsw70 commented 1 year ago

To start with: thank you for this great library, it is really useful. I am an amateur dev so apologies if the question is obvious.

When doing a .Lookup(), the data is extracted either into any or a struct created manually. Is there a reason why there is no type associated with the result that would encompass all the fields available as a result?

In other words, why isn't there a default struct such as the one in the example

var record struct {
    Country struct {
        ISOCode string `maxminddb:"iso_code"`
    } `maxminddb:"country"`
} // Or any appropriate struct

with all the available fields?

oschwald commented 1 year ago

The MMDB format allows for storing arbitrary data structures in the database. There isn't one record format. MaxMind has several different record structures for their different databases and other companies provide databases with other record structures. If you are primarily interested in using MaxMind databases, I suggest checking out github.com/oschwald/geoip2-golang, which uses this library to provide support for the various MaxMind databases. It will be slower than just reading the data you want, but it is easier to get started with.

wsw70 commented 1 year ago

Thank you very much for the update (and the libraries).

I like your avatar - if this was a pub I would probably go there.