Help us shape the future of Go! Take the 2026 Go Developer Survey

iploc

package module
v1.0.20261015 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 10 Imported by: 22

README

iploc - fastest ip country library

godoc release

Getting Started

try on https://play.golang.org/p/T_7jfSr0cE1

package main

import (
	"fmt"
	"net/netip"
	"github.com/phuslu/iploc"
)

func main() {
	fmt.Printf("%s", iploc.IPCountry(netip.MustParseAddr("1.1.1.1"))
}

// Output: US
Benchmarks
goos: windows
goarch: amd64
pkg: github.com/phuslu/iploc
cpu: 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
BenchmarkIPCountryForIPv4
BenchmarkIPCountryForIPv4-8     80750439                13.57 ns/op            0 B/op          0 allocs/op
BenchmarkIPCountryForIPv6
BenchmarkIPCountryForIPv6-8     57166812                20.44 ns/op            0 B/op          0 allocs/op
PASS
ok      github.com/phuslu/iploc 2.360s
Acknowledgment

This site or product includes IP2Location LITE data available from http://www.ip2location.com.

How often are the inlined ip data updated?

Following IP2Location Lite Database, usually monthly.

Documentation

Overview

Package iploc provides fastest IP to Country library for Go.

package main

import (
	"fmt"
	"net/netip"
	"github.com/phuslu/iploc"
)

func main() {
	fmt.Printf("%s", iploc.IPCountry(netip.MustParseAddr("1.1.1.1"))
}

// Output: US

Version is iplocation database version.

Index

Constants

View Source
const Version = "v1.0.20261015"

Version is iplocation database version.

Variables

This section is empty.

Functions

func Country

func Country(ip net.IP) (country string)

Country return ISO 3166-1 alpha-2 country code of IP.

func IPCountry added in v1.0.20240311

func IPCountry(ip netip.Addr) (country string)

IPCountry return ISO 3166-1 alpha-2 country code of IP.

Types

This section is empty.

Jump to

Keyboard shortcuts

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