oschwald / maxminddb-golang

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

Added Traverse method #6

Closed erikdubbelboer closed 9 years ago

erikdubbelboer commented 9 years ago

Add a method to traverse the loaded database. I personally use this to enumerate the database to extract all possible ISP's from it.

If you want I can add a simple example.

oschwald commented 9 years ago

I agree this functionality is useful, but, for many use cases, people need the network along with the result. I am also worried that reusing the same result between callback calls will cause confusion and bugs.

I wonder if this would be better implemented as some sort of iterator where caller controls the lifespan of the result. This would also remove the need to cast the result back to the original type in the callback.

erikdubbelboer commented 9 years ago

An iterator is actually a good idea and easy to implement. I also have a version that passes the net to the callback. I'll update the pull request when I have some time to fix it nicely.

erikdubbelboer commented 9 years ago

Sorry it took so long. Please check the new version I just committed. It now uses an iterator and I added a test case.

oschwald commented 9 years ago

Thanks! This looks good. I might take a shot at making it process the subnets in order. It should be doable by switching to depth-first traversal.

oschwald commented 9 years ago

I made some minor tweaks to this in the traverse branch to traverse in order and also to return the subnet (net.IPNet) for the record rather than just the first IP.

erikdubbelboer commented 9 years ago

That looks really good and quite a bit simpler :) You want me to update my pull request or you just merge your branch into master?

oschwald commented 9 years ago

Thanks. I'll merge it. I just want to add some additional tests. I'll hopefully get to it this weekend.

oschwald commented 9 years ago

Closing as this is in master already.