DEV.co
Open-Source Databases · oschwald

geoip2-golang

geoip2-golang is an unofficial Go library for reading MaxMind GeoIP2 and GeoLite2 geolocation databases. It supports multiple database types (City, Country, ASN, Anonymous IP) and provides IP-to-location lookups with performance improvements in v2.0.

Source: GitHub — github.com/oschwald/geoip2-golang
2.3k
GitHub stars
219
Forks
Go
Primary language
ISC
License (OSI-approved)

Key facts

Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.

FieldValue
Repositoryoschwald/geoip2-golang
Owneroschwald
Primary languageGo
LicenseISC — OSI-approved
Stars2.3k
Forks219
Open issues2
Latest releasev2.2.0 (2026-05-17)
Last updated2026-06-29
Sourcehttps://github.com/oschwald/geoip2-golang

What geoip2-golang is

Built on the maxminddb-golang reader, this library decodes MaxMind's .mmdb format databases using netip.Addr for IPv4/IPv6 queries. Version 2.0 delivers 56% fewer allocations and 34% less memory usage, with typed result structs and HasData() validation methods.

Quickstart

Get the geoip2-golang source

Clone the repository and explore it locally.

terminalbash
git clone https://github.com/oschwald/geoip2-golang.gitcd geoip2-golang# follow the project's README for install & configuration

Need it deployed, integrated, or customized instead? DEV.co ships production installs.

Best use cases

IP-based geo-targeting and localization

Determine user location from IP address to serve region-specific content, language preferences, or compliance rules (e.g., GDPR checks). Lightweight and performant for per-request lookups.

Fraud detection and risk scoring

Identify VPN, proxy, and hosting provider IPs using Anonymous IP database; flag suspicious geographic patterns for payment processing or account access.

ASN and ISP identification

Extract autonomous system numbers and organization names for network analysis, DDoS mitigation, or traffic classification in infrastructure monitoring.

Implementation considerations

  • Acquire MaxMind database files (.mmdb format) separately—free GeoLite2 requires registration; commercial GeoIP2 requires purchase.
  • Load and cache databases in memory at startup; database handles are thread-safe but expensive to reopen repeatedly.
  • Handle missing data gracefully using HasData() method; not all IPs will have complete records, especially for free GeoLite2.
  • Consider field-level optimization: if you only need country or ASN, use maxminddb's Lookup() directly with custom result structs for even better performance.
  • Plan for periodic database updates (MaxMind releases updates regularly); automate download and hot-reload if accuracy is critical.

When to avoid it — and what to weigh

  • Real-time accuracy is mission-critical — MaxMind databases are updated periodically (not real-time). If you need live, constantly refreshed geo data, this is not suitable; consider APIs with live feeds.
  • You require official MaxMind support — This is an unofficial community library. For production-critical use, MaxMind's official SDKs and their support channels may be preferred.
  • Your application runs on Go < 1.25 — Requires Go 1.25 or later. Legacy projects on older Go versions will need to stay on v1.x or upgrade their runtime.
  • Database licensing compliance is unclear — You must obtain or purchase MaxMind database files separately and comply with their terms. Using free GeoLite2 requires registration and adherence to MaxMind's license.

License & commercial use

Licensed under ISC License, a permissive open-source license that allows commercial use, modification, and distribution with minimal restrictions.

ISC License permits commercial use of the library code itself. However, commercial use of MaxMind databases (GeoIP2) requires a paid subscription from MaxMind. Free GeoLite2 databases have separate terms requiring registration and compliance with MaxMind's database license. Review MaxMind's licensing separately to confirm compliance.

DEV.co evaluation signals

Editorial assessment — not user reviews. Directional, with an explicit confidence level.

SignalAssessment
MaintenanceActive
DocumentationStrong
License clarityClear
Deployment complexityLow
DEV.co fitGood
Assessment confidenceHigh
Security considerations

Database files must be stored securely and kept current to reflect the latest threat intelligence on proxies and anonymous networks. Library itself has minimal attack surface (pure data lookup). Ensure MaxMind .mmdb files are validated before deployment. No known CVEs mentioned in the data; standard Go dependency scanning recommended. IP geolocation data carries privacy considerations (user location inference); ensure your use complies with regional privacy laws.

Alternatives to consider

MaxMind Official SDK (GeoIP2 Java, Python, .NET)

Official support and guaranteed API stability; choose if you need vendor backing or run non-Go services. Larger library surface and heavier dependencies.

IP2Location (standalone or API)

Competing commercial database provider with similar accuracy; some operators prefer to avoid MaxMind's registration/licensing terms or seek better country coverage.

GeoIPTify or similar lightweight REST API

Hosted API approach eliminates local database management but introduces latency and external dependency; suitable only if per-lookup latency is acceptable (typically not for high-throughput Go services).

Software development agency

Build on geoip2-golang with DEV.co software developers

Our engineers can advise on MaxMind database setup, API architecture, and deployment patterns for high-volume lookup services. Contact us to discuss your geolocation requirements.

Talk to DEV.co

Related open-source tools

Surfaced by semantic similarity across the DEV.co open-source index.

Related on DEV.co

Explore the category and the services that help you build with it.

geoip2-golang FAQ

Can I use this library commercially?
Yes. The library code (ISC License) permits commercial use. However, you must separately obtain MaxMind databases (free GeoLite2 with registration or paid GeoIP2) and comply with their licensing terms.
How often are the databases updated?
MaxMind updates its databases regularly (typically weekly for GeoLite2). You must download and refresh the .mmdb files independently; the library does not auto-update.
What is the performance impact?
v2.0 shows 56% fewer allocations and 34% less memory vs. v1. Queries are in-process and very fast (sub-millisecond). Latency is deterministic and predictable.
Is this library thread-safe?
Yes, the database handle is thread-safe for concurrent Lookup operations. You can safely call City(), Country(), ASN(), etc. from multiple goroutines without additional synchronization.

Software developers & web developers for hire

Need help beyond evaluating geoip2-golang? DEV.co is a software development agency offering software development services and web development for teams of every size. Our software developers and web developers build custom software, web applications, APIs, and open-source databases integrations — and maintain them long-term.

Need help integrating IP geolocation into your Go application?

Our engineers can advise on MaxMind database setup, API architecture, and deployment patterns for high-volume lookup services. Contact us to discuss your geolocation requirements.