ip3country-go

module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 28, 2023 License: ISC

README

ip3country-go

A zero-dependency, super small, IP address to 2-letter country code lookup library. There are already several libraries available, but none met our requirements for binary size and lookup speed.

This project in its entirety is <500KB, compared to most alternatives out there that are in the MBs (but might provide more than just countries).

The database used in this project is compacted from IP2Location. Their DB1.LITE edition is provided under CCA, with the attribution below:


NOTE

This site or product includes IP2Location LITE data available from https://lite.ip2location.com.


Usage

Add the dependency to your go.mod file:

require (
	github.com/statsig-io/ip3country-go v0.2.0
)
lookup := countrylookup.New()
// Lookup using ip4 str
countryCode, ok := lookup.LookupIp("123.45.67.8") // => 'KR'

// Lookup using numeric ip
countryCode, ok = lookup.LookupNumericIp(2066563848) // => 'KR'

Accuracy

ip3country's accuracy is dependent on IP2Location LITE's accuracy. In our experience, for country lookups, it is accurate enough for most applications.

IP2Location publishes accuracy reports here: https://www.ip2location.com/data-accuracy

There's also this third party report available: https://www.cl.cam.ac.uk/~nz247/publications/JSAC2011-Geolocation.pdf

Name

All variants of "ip2country" were already taken in npm when we published the original, nodejs verion. Now, we have re-created it for use in go applications (or as a binary in other languages)

Motivation

At Statsig, we needed a library to evaluate location-based conditions on Feature Gates (Feature Flags). We use ip3country to power country-level rollouts or A/B tests for new features.

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL