geoip

package module
v0.0.0-...-85a7860 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2025 License: MIT Imports: 6 Imported by: 2

README

geoip

Go Reference Go Report Card

go get git.gorbe.io/go/geoip@latest

Get the latest commit (if Go module proxy is not updated):

go get "git.gorbe.io/go/geoip@$(curl -s 'https://git.gorbe.io/api/v1/repos/go/geoip/commits' | jq -r '.[0].sha')"

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoData             = errors.New("No Data")
	ErrInvalidCountryCode = errors.New("invalid Country Code")
)
View Source
var (
	//go:embed db/GeoLite2-ASN.mmdb
	GeoLite2ASN []byte

	//go:embed db/GeoLite2-City.mmdb
	GeoLite2City []byte

	//go:embed db/GeoLite2-Country.mmdb
	GeoLite2Country []byte
)

Functions

func VaidateCountryCode

func VaidateCountryCode(v string) bool

ValidateCountryCode returns whether string v is a valid two-character ISO 3166-1 country code.

Types

type ASN

type ASN struct {
	Organization string `maxminddb:"autonomous_system_organization"`
	Number       uint   `maxminddb:"autonomous_system_number"`
}

func (*ASN) String

func (a *ASN) String() string

func (*ASN) UnmarshalMaxMindDB

func (a *ASN) UnmarshalMaxMindDB(d *mmdbdata.Decoder) error

UnmarshalMaxMindDB implements the github.com/oschwald/maxminddb-golang/v2/mmdbdata.Unmarshaler interface

type Country

type Country struct {
	Name string // Full name of the country (eg.: "Hungary")
	Code string // Two-character ISO 3166-1 country code (eg.: "HU")
}

func (*Country) String

func (c *Country) String() string

func (*Country) UnmarshalMaxMindDB

func (c *Country) UnmarshalMaxMindDB(d *mmdbdata.Decoder) error

UnmarshalMaxMindDB implements the github.com/oschwald/maxminddb-golang/v2/mmdbdata.Unmarshaler interface

type GeoIP

type GeoIP struct {
	// contains filtered or unexported fields
}

func NewGeoIPFromBytes

func NewGeoIPFromBytes(b []byte) (*GeoIP, error)

NewGeoIPFromBytes parses mmdb bytes b and returns a pointer to GeoIP.

func NewGeoIPFromFile

func NewGeoIPFromFile(path string) (*GeoIP, error)

NewGeoIPFromFile parses an mmdb file in path and returns a pointer to GeoIP.

func (*GeoIP) ASN

func (g *GeoIP) ASN(addr netip.Addr) (*ASN, error)

ASN returns the ASN associated with the IP address addr.

If no data found for the given address, returns ErrNoData.

func (*GeoIP) Country

func (g *GeoIP) Country(addr netip.Addr) (*Country, error)

Country returns the country associated with IP address addr.

If no data found for the given address, returns ErrNoData.

func (*GeoIP) IsASN

func (g *GeoIP) IsASN(addr netip.Addr, n uint) (bool, error)

IsASN returns whether IP address addr belong to ASN Number n.

If no data found for the given address, returns ErrNoData.

func (*GeoIP) IsCountry

func (g *GeoIP) IsCountry(addr netip.Addr, code string) (bool, error)

IsCountry returns whether IP address addr is assocated with the country code. The country code must be in ISO 3166-1 two-character format (eg.: "HU").

If code is invalid, returns[ErrInvalidCountryCode]. If no data found for the given address, returns ErrNoData.

type GeoIPs

type GeoIPs struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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