Go SDK · Feature

IP Geolocation in Go

Turn any IP address into geolocation, network, and threat intelligence with one call. The LookupIP method on the official ipapi-go client returns the country, city, coordinates, timezone, ISP, and ASN of an IP — plus the SuspiciousFactors flags used for fraud screening — in a single typed response.

Trusted by thousands of businesses
Fast JSON API responses
Real-time validation
Simple integration, SDKs & examples
What it does

Geolocation without browser GPS

IP-based geolocation works entirely server-side — no permission prompt, no client SDK, and it works for every visitor and every log line you already have. ip-api.io resolves an IP to a physical location and, uniquely, returns security signals (VPN, proxy, Tor, datacenter, threat) in the same response, so you can localize content and screen for fraud in one round trip.

Prerequisites

  • Go 1.21 or higher
  • The ipapi-go module installed (go get github.com/ip-api-io/ipapi-go)
  • A free ip-api.io API key
1

Geolocate one IP with LookupIP

Pass any IPv4 or IPv6 address, or use Lookup(ctx) to geolocate the caller's own IP. Nullable fields are pointers — guard before dereferencing.

client := ipapi.NewClient(ipapi.WithAPIKey(os.Getenv("IP_API_IO_KEY")))
ctx := context.Background()

info, err := client.LookupIP(ctx, "8.8.8.8")
if err != nil {
	log.Fatal(err)
}

fmt.Println(info.IP)                              // "8.8.8.8"
if info.ISP != nil {
	fmt.Println(*info.ISP)                       // "Google LLC"
}
if info.Location.Country != nil {
	fmt.Println(*info.Location.Country)          // "United States"
}
fmt.Println(info.SuspiciousFactors.IsDatacenter) // true

Resolve the IP of the machine making the request by calling Lookup(ctx):

me, _ := client.Lookup(ctx)
fmt.Println(me.IP)
Behind a proxy? Pass the real client IP from the X-Forwarded-For header to LookupIP(ctx, ip) rather than relying on the socket address. See the SDK overview for an HTTP handler example.
2

Geolocate up to 100 IPs with LookupBatch

Enrich logs, sign-up events, or historical data without a round trip per IP. The SDK returns an error if the slice is empty or longer than 100.

batch, err := client.LookupBatch(ctx, []string{"8.8.8.8", "1.1.1.1", "9.9.9.9"})
if err != nil {
	log.Fatal(err)
}

fmt.Println(batch.TotalProcessed)    // 3
fmt.Println(batch.SuccessfulLookups) // 3
fmt.Println(batch.FailedLookups)     // 0

for ip, info := range batch.Results {
	fmt.Println(ip, info.SuspiciousFactors.IsVPN)
}
Reference

Response reference

LookupIP() returns a typed *IPInfo. Nullable fields are pointers — nil for private or unrecognized addresses.

FieldTypeDescription
IPstringThe looked-up address
ISP*stringInternet service provider
ASN*stringAutonomous system the IP belongs to
LocationLocationCountry, CountryCode, City, Latitude, Longitude, Zip, Timezone, LocalTime, LocalTimeUnix, IsDaylightSavings (nullable → pointers)
SuspiciousFactorsSuspiciousFactorsIsProxy, IsVPN, IsTorNode, IsDatacenter, IsSpam, IsCrawler, IsThreat
FAQ

Frequently asked questions

How do I get the location of an IP address in Go?

Install ipapi-go, construct a client with your API key, and call client.LookupIP(ctx, ip). The returned *IPInfo has a Location struct with country, city, latitude, longitude and timezone, plus a SuspiciousFactors struct with VPN/proxy/Tor flags.

How do I geolocate the caller's own IP?

Call client.Lookup(ctx) with no IP argument and the API resolves the IP from the request. Behind a proxy, pass the real client IP from the X-Forwarded-For header to client.LookupIP(ctx, ip) instead.

How do I look up many IP addresses at once?

Use client.LookupBatch(ctx, ips) with up to 100 addresses in one request. It returns Results (a map[string]IPInfo) plus TotalProcessed, SuccessfulLookups and FailedLookups, and returns an error if the slice is empty or longer than 100.

Why are some fields pointers?

Nullable location fields such as Country and City are *string because they're absent for private ranges or unrecognized addresses — guard with a nil check before dereferencing. Boolean flags like IsVPN are plain values.

Start building with the ip-api.io Go SDK

Run go get github.com/ip-api-io/ipapi-go, drop in your free API key, and ship in minutes — one typed, context-aware client for geolocation, fraud detection, and email validation.

Need support?

Explore how IP-API.io can enhance your security, provide robust bot protection, and improve IP geolocation accuracy for your applications.

Contact Support

Found a bug in the SDK?

The ipapi-go module is open source. Open an issue or pull request on GitHub and we'll take a look.

Open on GitHub