geoip

package
v0.0.0-...-b6e3791 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package geoip contains implementations of the GeoIP database for AdGuard DNS.

Index

Constants

This section is empty.

Variables

View Source
var DefaultCountryTopASNs = map[Country]ASN{}/* 232 elements not displayed */

DefaultCountryTopASNs is a mapping of a country to their top ASNs.

View Source
var DefaultTopASNs = map[ASN]struct{}{}/* 3153 elements not displayed */

DefaultTopASNs contains all specially handled ASNs.

Functions

This section is empty.

Types

type ASN

type ASN uint32

ASN is the autonomous system number of an IP address.

See also https://datatracker.ietf.org/doc/html/rfc7300.

type Continent

type Continent string

Continent represents a continent code used by MaxMind.

const (
	// ContinentNone is an unknown continent code.
	ContinentNone Continent = ""
	// ContinentAF is Africa.
	ContinentAF Continent = "AF"
	// ContinentAN is Antarctica.
	ContinentAN Continent = "AN"
	// ContinentAS is Asia.
	ContinentAS Continent = "AS"
	// ContinentEU is Europe.
	ContinentEU Continent = "EU"
	// ContinentNA is North America.
	ContinentNA Continent = "NA"
	// ContinentOC is Oceania.
	ContinentOC Continent = "OC"
	// ContinentSA is South America.
	ContinentSA Continent = "SA"
)

Continent code constants.

func NewContinent

func NewContinent(s string) (c Continent, err error)

NewContinent converts s into a Continent while also validating it. Prefer to use this instead of a plain conversion.

type Country

type Country string

Country represents an ISO 3166-1 alpha-2 country code.

const (
	// CountryNone is an invalid or unknown country code.
	CountryNone Country = ""
	// CountryAD is the ISO 3166-1 alpha-2 code for
	// Andorra.
	CountryAD Country = "AD"
	// CountryAE is the ISO 3166-1 alpha-2 code for
	// United Arab Emirates.
	CountryAE Country = "AE"
	// CountryAF is the ISO 3166-1 alpha-2 code for
	// Afghanistan.
	CountryAF Country = "AF"
	// CountryAG is the ISO 3166-1 alpha-2 code for
	// Antigua and Barbuda.
	CountryAG Country = "AG"
	// CountryAI is the ISO 3166-1 alpha-2 code for
	// Anguilla.
	CountryAI Country = "AI"
	// CountryAL is the ISO 3166-1 alpha-2 code for
	// Albania.
	CountryAL Country = "AL"
	// CountryAM is the ISO 3166-1 alpha-2 code for
	// Armenia.
	CountryAM Country = "AM"
	// CountryAO is the ISO 3166-1 alpha-2 code for
	// Angola.
	CountryAO Country = "AO"
	// CountryAQ is the ISO 3166-1 alpha-2 code for
	// Antarctica.
	CountryAQ Country = "AQ"
	// CountryAR is the ISO 3166-1 alpha-2 code for
	// Argentina.
	CountryAR Country = "AR"
	// CountryAS is the ISO 3166-1 alpha-2 code for
	// American Samoa.
	CountryAS Country = "AS"
	// CountryAT is the ISO 3166-1 alpha-2 code for
	// Austria.
	CountryAT Country = "AT"
	// CountryAU is the ISO 3166-1 alpha-2 code for
	// Australia.
	CountryAU Country = "AU"
	// CountryAW is the ISO 3166-1 alpha-2 code for
	// Aruba.
	CountryAW Country = "AW"
	// CountryAX is the ISO 3166-1 alpha-2 code for
	// Åland Islands.
	CountryAX Country = "AX"
	// CountryAZ is the ISO 3166-1 alpha-2 code for
	// Azerbaijan.
	CountryAZ Country = "AZ"
	// CountryBA is the ISO 3166-1 alpha-2 code for
	// Bosnia and Herzegovina.
	CountryBA Country = "BA"
	// CountryBB is the ISO 3166-1 alpha-2 code for
	// Barbados.
	CountryBB Country = "BB"
	// CountryBD is the ISO 3166-1 alpha-2 code for
	// Bangladesh.
	CountryBD Country = "BD"
	// CountryBE is the ISO 3166-1 alpha-2 code for
	// Belgium.
	CountryBE Country = "BE"
	// CountryBF is the ISO 3166-1 alpha-2 code for
	// Burkina Faso.
	CountryBF Country = "BF"
	// CountryBG is the ISO 3166-1 alpha-2 code for
	// Bulgaria.
	CountryBG Country = "BG"
	// CountryBH is the ISO 3166-1 alpha-2 code for
	// Bahrain.
	CountryBH Country = "BH"
	// CountryBI is the ISO 3166-1 alpha-2 code for
	// Burundi.
	CountryBI Country = "BI"
	// CountryBJ is the ISO 3166-1 alpha-2 code for
	// Benin.
	CountryBJ Country = "BJ"
	// CountryBL is the ISO 3166-1 alpha-2 code for
	// Saint Barthélemy.
	CountryBL Country = "BL"
	// CountryBM is the ISO 3166-1 alpha-2 code for
	// Bermuda.
	CountryBM Country = "BM"
	// CountryBN is the ISO 3166-1 alpha-2 code for
	// Brunei Darussalam.
	CountryBN Country = "BN"
	// CountryBO is the ISO 3166-1 alpha-2 code for
	// Bolivia (Plurinational State of).
	CountryBO Country = "BO"
	// CountryBQ is the ISO 3166-1 alpha-2 code for
	// Bonaire, Sint Eustatius and Saba.
	CountryBQ Country = "BQ"
	// CountryBR is the ISO 3166-1 alpha-2 code for
	// Brazil.
	CountryBR Country = "BR"
	// CountryBS is the ISO 3166-1 alpha-2 code for
	// Bahamas.
	CountryBS Country = "BS"
	// CountryBT is the ISO 3166-1 alpha-2 code for
	// Bhutan.
	CountryBT Country = "BT"
	// CountryBV is the ISO 3166-1 alpha-2 code for
	// Bouvet Island.
	CountryBV Country = "BV"
	// CountryBW is the ISO 3166-1 alpha-2 code for
	// Botswana.
	CountryBW Country = "BW"
	// CountryBY is the ISO 3166-1 alpha-2 code for
	// Belarus.
	CountryBY Country = "BY"
	// CountryBZ is the ISO 3166-1 alpha-2 code for
	// Belize.
	CountryBZ Country = "BZ"
	// CountryCA is the ISO 3166-1 alpha-2 code for
	// Canada.
	CountryCA Country = "CA"
	// CountryCC is the ISO 3166-1 alpha-2 code for
	// Cocos (Keeling) Islands.
	CountryCC Country = "CC"
	// CountryCD is the ISO 3166-1 alpha-2 code for
	// Congo, Democratic Republic of the.
	CountryCD Country = "CD"
	// CountryCF is the ISO 3166-1 alpha-2 code for
	// Central African Republic.
	CountryCF Country = "CF"
	// CountryCG is the ISO 3166-1 alpha-2 code for
	// Congo.
	CountryCG Country = "CG"
	// CountryCH is the ISO 3166-1 alpha-2 code for
	// Switzerland.
	CountryCH Country = "CH"
	// CountryCI is the ISO 3166-1 alpha-2 code for
	// Côte d'Ivoire.
	CountryCI Country = "CI"
	// CountryCK is the ISO 3166-1 alpha-2 code for
	// Cook Islands.
	CountryCK Country = "CK"
	// CountryCL is the ISO 3166-1 alpha-2 code for
	// Chile.
	CountryCL Country = "CL"
	// CountryCM is the ISO 3166-1 alpha-2 code for
	// Cameroon.
	CountryCM Country = "CM"
	// CountryCN is the ISO 3166-1 alpha-2 code for
	// China.
	CountryCN Country = "CN"
	// CountryCO is the ISO 3166-1 alpha-2 code for
	// Colombia.
	CountryCO Country = "CO"
	// CountryCR is the ISO 3166-1 alpha-2 code for
	// Costa Rica.
	CountryCR Country = "CR"
	// CountryCU is the ISO 3166-1 alpha-2 code for
	// Cuba.
	CountryCU Country = "CU"
	// CountryCV is the ISO 3166-1 alpha-2 code for
	// Cabo Verde.
	CountryCV Country = "CV"
	// CountryCW is the ISO 3166-1 alpha-2 code for
	// Curaçao.
	CountryCW Country = "CW"
	// CountryCX is the ISO 3166-1 alpha-2 code for
	// Christmas Island.
	CountryCX Country = "CX"
	// CountryCY is the ISO 3166-1 alpha-2 code for
	// Cyprus.
	CountryCY Country = "CY"
	// CountryCZ is the ISO 3166-1 alpha-2 code for
	// Czechia.
	CountryCZ Country = "CZ"
	// CountryDE is the ISO 3166-1 alpha-2 code for
	// Germany.
	CountryDE Country = "DE"
	// CountryDJ is the ISO 3166-1 alpha-2 code for
	// Djibouti.
	CountryDJ Country = "DJ"
	// CountryDK is the ISO 3166-1 alpha-2 code for
	// Denmark.
	CountryDK Country = "DK"
	// CountryDM is the ISO 3166-1 alpha-2 code for
	// Dominica.
	CountryDM Country = "DM"
	// CountryDO is the ISO 3166-1 alpha-2 code for
	// Dominican Republic.
	CountryDO Country = "DO"
	// CountryDZ is the ISO 3166-1 alpha-2 code for
	// Algeria.
	CountryDZ Country = "DZ"
	// CountryEC is the ISO 3166-1 alpha-2 code for
	// Ecuador.
	CountryEC Country = "EC"
	// CountryEE is the ISO 3166-1 alpha-2 code for
	// Estonia.
	CountryEE Country = "EE"
	// CountryEG is the ISO 3166-1 alpha-2 code for
	// Egypt.
	CountryEG Country = "EG"
	// CountryEH is the ISO 3166-1 alpha-2 code for
	// Western Sahara.
	CountryEH Country = "EH"
	// CountryER is the ISO 3166-1 alpha-2 code for
	// Eritrea.
	CountryER Country = "ER"
	// CountryES is the ISO 3166-1 alpha-2 code for
	// Spain.
	CountryES Country = "ES"
	// CountryET is the ISO 3166-1 alpha-2 code for
	// Ethiopia.
	CountryET Country = "ET"
	// CountryFI is the ISO 3166-1 alpha-2 code for
	// Finland.
	CountryFI Country = "FI"
	// CountryFJ is the ISO 3166-1 alpha-2 code for
	// Fiji.
	CountryFJ Country = "FJ"
	// CountryFK is the ISO 3166-1 alpha-2 code for
	// Falkland Islands (Malvinas).
	CountryFK Country = "FK"
	// CountryFM is the ISO 3166-1 alpha-2 code for
	// Micronesia (Federated States of).
	CountryFM Country = "FM"
	// CountryFO is the ISO 3166-1 alpha-2 code for
	// Faroe Islands.
	CountryFO Country = "FO"
	// CountryFR is the ISO 3166-1 alpha-2 code for
	// France.
	CountryFR Country = "FR"
	// CountryGA is the ISO 3166-1 alpha-2 code for
	// Gabon.
	CountryGA Country = "GA"
	// CountryGB is the ISO 3166-1 alpha-2 code for
	// United Kingdom of Great Britain and Northern Ireland.
	CountryGB Country = "GB"
	// CountryGD is the ISO 3166-1 alpha-2 code for
	// Grenada.
	CountryGD Country = "GD"
	// CountryGE is the ISO 3166-1 alpha-2 code for
	// Georgia.
	CountryGE Country = "GE"
	// CountryGF is the ISO 3166-1 alpha-2 code for
	// French Guiana.
	CountryGF Country = "GF"
	// CountryGG is the ISO 3166-1 alpha-2 code for
	// Guernsey.
	CountryGG Country = "GG"
	// CountryGH is the ISO 3166-1 alpha-2 code for
	// Ghana.
	CountryGH Country = "GH"
	// CountryGI is the ISO 3166-1 alpha-2 code for
	// Gibraltar.
	CountryGI Country = "GI"
	// CountryGL is the ISO 3166-1 alpha-2 code for
	// Greenland.
	CountryGL Country = "GL"
	// CountryGM is the ISO 3166-1 alpha-2 code for
	// Gambia.
	CountryGM Country = "GM"
	// CountryGN is the ISO 3166-1 alpha-2 code for
	// Guinea.
	CountryGN Country = "GN"
	// CountryGP is the ISO 3166-1 alpha-2 code for
	// Guadeloupe.
	CountryGP Country = "GP"
	// CountryGQ is the ISO 3166-1 alpha-2 code for
	// Equatorial Guinea.
	CountryGQ Country = "GQ"
	// CountryGR is the ISO 3166-1 alpha-2 code for
	// Greece.
	CountryGR Country = "GR"
	// CountryGS is the ISO 3166-1 alpha-2 code for
	// South Georgia and the South Sandwich Islands.
	CountryGS Country = "GS"
	// CountryGT is the ISO 3166-1 alpha-2 code for
	// Guatemala.
	CountryGT Country = "GT"
	// CountryGU is the ISO 3166-1 alpha-2 code for
	// Guam.
	CountryGU Country = "GU"
	// CountryGW is the ISO 3166-1 alpha-2 code for
	// Guinea-Bissau.
	CountryGW Country = "GW"
	// CountryGY is the ISO 3166-1 alpha-2 code for
	// Guyana.
	CountryGY Country = "GY"
	// CountryHK is the ISO 3166-1 alpha-2 code for
	// Hong Kong.
	CountryHK Country = "HK"
	// CountryHM is the ISO 3166-1 alpha-2 code for
	// Heard Island and McDonald Islands.
	CountryHM Country = "HM"
	// CountryHN is the ISO 3166-1 alpha-2 code for
	// Honduras.
	CountryHN Country = "HN"
	// CountryHR is the ISO 3166-1 alpha-2 code for
	// Croatia.
	CountryHR Country = "HR"
	// CountryHT is the ISO 3166-1 alpha-2 code for
	// Haiti.
	CountryHT Country = "HT"
	// CountryHU is the ISO 3166-1 alpha-2 code for
	// Hungary.
	CountryHU Country = "HU"
	// CountryID is the ISO 3166-1 alpha-2 code for
	// Indonesia.
	CountryID Country = "ID"
	// CountryIE is the ISO 3166-1 alpha-2 code for
	// Ireland.
	CountryIE Country = "IE"
	// CountryIL is the ISO 3166-1 alpha-2 code for
	// Israel.
	CountryIL Country = "IL"
	// CountryIM is the ISO 3166-1 alpha-2 code for
	// Isle of Man.
	CountryIM Country = "IM"
	// CountryIN is the ISO 3166-1 alpha-2 code for
	// India.
	CountryIN Country = "IN"
	// CountryIO is the ISO 3166-1 alpha-2 code for
	// British Indian Ocean Territory.
	CountryIO Country = "IO"
	// CountryIQ is the ISO 3166-1 alpha-2 code for
	// Iraq.
	CountryIQ Country = "IQ"
	// CountryIR is the ISO 3166-1 alpha-2 code for
	// Iran (Islamic Republic of).
	CountryIR Country = "IR"
	// CountryIS is the ISO 3166-1 alpha-2 code for
	// Iceland.
	CountryIS Country = "IS"
	// CountryIT is the ISO 3166-1 alpha-2 code for
	// Italy.
	CountryIT Country = "IT"
	// CountryJE is the ISO 3166-1 alpha-2 code for
	// Jersey.
	CountryJE Country = "JE"
	// CountryJM is the ISO 3166-1 alpha-2 code for
	// Jamaica.
	CountryJM Country = "JM"
	// CountryJO is the ISO 3166-1 alpha-2 code for
	// Jordan.
	CountryJO Country = "JO"
	// CountryJP is the ISO 3166-1 alpha-2 code for
	// Japan.
	CountryJP Country = "JP"
	// CountryKE is the ISO 3166-1 alpha-2 code for
	// Kenya.
	CountryKE Country = "KE"
	// CountryKG is the ISO 3166-1 alpha-2 code for
	// Kyrgyzstan.
	CountryKG Country = "KG"
	// CountryKH is the ISO 3166-1 alpha-2 code for
	// Cambodia.
	CountryKH Country = "KH"
	// CountryKI is the ISO 3166-1 alpha-2 code for
	// Kiribati.
	CountryKI Country = "KI"
	// CountryKM is the ISO 3166-1 alpha-2 code for
	// Comoros.
	CountryKM Country = "KM"
	// CountryKN is the ISO 3166-1 alpha-2 code for
	// Saint Kitts and Nevis.
	CountryKN Country = "KN"
	// CountryKP is the ISO 3166-1 alpha-2 code for
	// Korea (Democratic People's Republic of).
	CountryKP Country = "KP"
	// CountryKR is the ISO 3166-1 alpha-2 code for
	// Korea, Republic of.
	CountryKR Country = "KR"
	// CountryKW is the ISO 3166-1 alpha-2 code for
	// Kuwait.
	CountryKW Country = "KW"
	// CountryKY is the ISO 3166-1 alpha-2 code for
	// Cayman Islands.
	CountryKY Country = "KY"
	// CountryKZ is the ISO 3166-1 alpha-2 code for
	// Kazakhstan.
	CountryKZ Country = "KZ"
	// CountryLA is the ISO 3166-1 alpha-2 code for
	// Lao People's Democratic Republic.
	CountryLA Country = "LA"
	// CountryLB is the ISO 3166-1 alpha-2 code for
	// Lebanon.
	CountryLB Country = "LB"
	// CountryLC is the ISO 3166-1 alpha-2 code for
	// Saint Lucia.
	CountryLC Country = "LC"
	// CountryLI is the ISO 3166-1 alpha-2 code for
	// Liechtenstein.
	CountryLI Country = "LI"
	// CountryLK is the ISO 3166-1 alpha-2 code for
	// Sri Lanka.
	CountryLK Country = "LK"
	// CountryLR is the ISO 3166-1 alpha-2 code for
	// Liberia.
	CountryLR Country = "LR"
	// CountryLS is the ISO 3166-1 alpha-2 code for
	// Lesotho.
	CountryLS Country = "LS"
	// CountryLT is the ISO 3166-1 alpha-2 code for
	// Lithuania.
	CountryLT Country = "LT"
	// CountryLU is the ISO 3166-1 alpha-2 code for
	// Luxembourg.
	CountryLU Country = "LU"
	// CountryLV is the ISO 3166-1 alpha-2 code for
	// Latvia.
	CountryLV Country = "LV"
	// CountryLY is the ISO 3166-1 alpha-2 code for
	// Libya.
	CountryLY Country = "LY"
	// CountryMA is the ISO 3166-1 alpha-2 code for
	// Morocco.
	CountryMA Country = "MA"
	// CountryMC is the ISO 3166-1 alpha-2 code for
	// Monaco.
	CountryMC Country = "MC"
	// CountryMD is the ISO 3166-1 alpha-2 code for
	// Moldova, Republic of.
	CountryMD Country = "MD"
	// CountryME is the ISO 3166-1 alpha-2 code for
	// Montenegro.
	CountryME Country = "ME"
	// CountryMF is the ISO 3166-1 alpha-2 code for
	// Saint Martin (French part).
	CountryMF Country = "MF"
	// CountryMG is the ISO 3166-1 alpha-2 code for
	// Madagascar.
	CountryMG Country = "MG"
	// CountryMH is the ISO 3166-1 alpha-2 code for
	// Marshall Islands.
	CountryMH Country = "MH"
	// CountryMK is the ISO 3166-1 alpha-2 code for
	// North Macedonia.
	CountryMK Country = "MK"
	// CountryML is the ISO 3166-1 alpha-2 code for
	// Mali.
	CountryML Country = "ML"
	// CountryMM is the ISO 3166-1 alpha-2 code for
	// Myanmar.
	CountryMM Country = "MM"
	// CountryMN is the ISO 3166-1 alpha-2 code for
	// Mongolia.
	CountryMN Country = "MN"
	// CountryMO is the ISO 3166-1 alpha-2 code for
	// Macao.
	CountryMO Country = "MO"
	// CountryMP is the ISO 3166-1 alpha-2 code for
	// Northern Mariana Islands.
	CountryMP Country = "MP"
	// CountryMQ is the ISO 3166-1 alpha-2 code for
	// Martinique.
	CountryMQ Country = "MQ"
	// CountryMR is the ISO 3166-1 alpha-2 code for
	// Mauritania.
	CountryMR Country = "MR"
	// CountryMS is the ISO 3166-1 alpha-2 code for
	// Montserrat.
	CountryMS Country = "MS"
	// CountryMT is the ISO 3166-1 alpha-2 code for
	// Malta.
	CountryMT Country = "MT"
	// CountryMU is the ISO 3166-1 alpha-2 code for
	// Mauritius.
	CountryMU Country = "MU"
	// CountryMV is the ISO 3166-1 alpha-2 code for
	// Maldives.
	CountryMV Country = "MV"
	// CountryMW is the ISO 3166-1 alpha-2 code for
	// Malawi.
	CountryMW Country = "MW"
	// CountryMX is the ISO 3166-1 alpha-2 code for
	// Mexico.
	CountryMX Country = "MX"
	// CountryMY is the ISO 3166-1 alpha-2 code for
	// Malaysia.
	CountryMY Country = "MY"
	// CountryMZ is the ISO 3166-1 alpha-2 code for
	// Mozambique.
	CountryMZ Country = "MZ"
	// CountryNA is the ISO 3166-1 alpha-2 code for
	// Namibia.
	CountryNA Country = "NA"
	// CountryNC is the ISO 3166-1 alpha-2 code for
	// New Caledonia.
	CountryNC Country = "NC"
	// CountryNE is the ISO 3166-1 alpha-2 code for
	// Niger.
	CountryNE Country = "NE"
	// CountryNF is the ISO 3166-1 alpha-2 code for
	// Norfolk Island.
	CountryNF Country = "NF"
	// CountryNG is the ISO 3166-1 alpha-2 code for
	// Nigeria.
	CountryNG Country = "NG"
	// CountryNI is the ISO 3166-1 alpha-2 code for
	// Nicaragua.
	CountryNI Country = "NI"
	// CountryNL is the ISO 3166-1 alpha-2 code for
	// Netherlands.
	CountryNL Country = "NL"
	// CountryNO is the ISO 3166-1 alpha-2 code for
	// Norway.
	CountryNO Country = "NO"
	// CountryNP is the ISO 3166-1 alpha-2 code for
	// Nepal.
	CountryNP Country = "NP"
	// CountryNR is the ISO 3166-1 alpha-2 code for
	// Nauru.
	CountryNR Country = "NR"
	// CountryNU is the ISO 3166-1 alpha-2 code for
	// Niue.
	CountryNU Country = "NU"
	// CountryNZ is the ISO 3166-1 alpha-2 code for
	// New Zealand.
	CountryNZ Country = "NZ"
	// CountryOM is the ISO 3166-1 alpha-2 code for
	// Oman.
	CountryOM Country = "OM"
	// CountryPA is the ISO 3166-1 alpha-2 code for
	// Panama.
	CountryPA Country = "PA"
	// CountryPE is the ISO 3166-1 alpha-2 code for
	// Peru.
	CountryPE Country = "PE"
	// CountryPF is the ISO 3166-1 alpha-2 code for
	// French Polynesia.
	CountryPF Country = "PF"
	// CountryPG is the ISO 3166-1 alpha-2 code for
	// Papua New Guinea.
	CountryPG Country = "PG"
	// CountryPH is the ISO 3166-1 alpha-2 code for
	// Philippines.
	CountryPH Country = "PH"
	// CountryPK is the ISO 3166-1 alpha-2 code for
	// Pakistan.
	CountryPK Country = "PK"
	// CountryPL is the ISO 3166-1 alpha-2 code for
	// Poland.
	CountryPL Country = "PL"
	// CountryPM is the ISO 3166-1 alpha-2 code for
	// Saint Pierre and Miquelon.
	CountryPM Country = "PM"
	// CountryPN is the ISO 3166-1 alpha-2 code for
	// Pitcairn.
	CountryPN Country = "PN"
	// CountryPR is the ISO 3166-1 alpha-2 code for
	// Puerto Rico.
	CountryPR Country = "PR"
	// CountryPS is the ISO 3166-1 alpha-2 code for
	// Palestine, State of.
	CountryPS Country = "PS"
	// CountryPT is the ISO 3166-1 alpha-2 code for
	// Portugal.
	CountryPT Country = "PT"
	// CountryPW is the ISO 3166-1 alpha-2 code for
	// Palau.
	CountryPW Country = "PW"
	// CountryPY is the ISO 3166-1 alpha-2 code for
	// Paraguay.
	CountryPY Country = "PY"
	// CountryQA is the ISO 3166-1 alpha-2 code for
	// Qatar.
	CountryQA Country = "QA"
	// CountryRE is the ISO 3166-1 alpha-2 code for
	// Réunion.
	CountryRE Country = "RE"
	// CountryRO is the ISO 3166-1 alpha-2 code for
	// Romania.
	CountryRO Country = "RO"
	// CountryRS is the ISO 3166-1 alpha-2 code for
	// Serbia.
	CountryRS Country = "RS"
	// CountryRU is the ISO 3166-1 alpha-2 code for
	// Russian Federation.
	CountryRU Country = "RU"
	// CountryRW is the ISO 3166-1 alpha-2 code for
	// Rwanda.
	CountryRW Country = "RW"
	// CountrySA is the ISO 3166-1 alpha-2 code for
	// Saudi Arabia.
	CountrySA Country = "SA"
	// CountrySB is the ISO 3166-1 alpha-2 code for
	// Solomon Islands.
	CountrySB Country = "SB"
	// CountrySC is the ISO 3166-1 alpha-2 code for
	// Seychelles.
	CountrySC Country = "SC"
	// CountrySD is the ISO 3166-1 alpha-2 code for
	// Sudan.
	CountrySD Country = "SD"
	// CountrySE is the ISO 3166-1 alpha-2 code for
	// Sweden.
	CountrySE Country = "SE"
	// CountrySG is the ISO 3166-1 alpha-2 code for
	// Singapore.
	CountrySG Country = "SG"
	// CountrySH is the ISO 3166-1 alpha-2 code for
	// Saint Helena, Ascension and Tristan da Cunha.
	CountrySH Country = "SH"
	// CountrySI is the ISO 3166-1 alpha-2 code for
	// Slovenia.
	CountrySI Country = "SI"
	// CountrySJ is the ISO 3166-1 alpha-2 code for
	// Svalbard and Jan Mayen.
	CountrySJ Country = "SJ"
	// CountrySK is the ISO 3166-1 alpha-2 code for
	// Slovakia.
	CountrySK Country = "SK"
	// CountrySL is the ISO 3166-1 alpha-2 code for
	// Sierra Leone.
	CountrySL Country = "SL"
	// CountrySM is the ISO 3166-1 alpha-2 code for
	// San Marino.
	CountrySM Country = "SM"
	// CountrySN is the ISO 3166-1 alpha-2 code for
	// Senegal.
	CountrySN Country = "SN"
	// CountrySO is the ISO 3166-1 alpha-2 code for
	// Somalia.
	CountrySO Country = "SO"
	// CountrySR is the ISO 3166-1 alpha-2 code for
	// Suriname.
	CountrySR Country = "SR"
	// CountrySS is the ISO 3166-1 alpha-2 code for
	// South Sudan.
	CountrySS Country = "SS"
	// CountryST is the ISO 3166-1 alpha-2 code for
	// Sao Tome and Principe.
	CountryST Country = "ST"
	// CountrySV is the ISO 3166-1 alpha-2 code for
	// El Salvador.
	CountrySV Country = "SV"
	// CountrySX is the ISO 3166-1 alpha-2 code for
	// Sint Maarten (Dutch part).
	CountrySX Country = "SX"
	// CountrySY is the ISO 3166-1 alpha-2 code for
	// Syrian Arab Republic.
	CountrySY Country = "SY"
	// CountrySZ is the ISO 3166-1 alpha-2 code for
	// Eswatini.
	CountrySZ Country = "SZ"
	// CountryTC is the ISO 3166-1 alpha-2 code for
	// Turks and Caicos Islands.
	CountryTC Country = "TC"
	// CountryTD is the ISO 3166-1 alpha-2 code for
	// Chad.
	CountryTD Country = "TD"
	// CountryTF is the ISO 3166-1 alpha-2 code for
	// French Southern Territories.
	CountryTF Country = "TF"
	// CountryTG is the ISO 3166-1 alpha-2 code for
	// Togo.
	CountryTG Country = "TG"
	// CountryTH is the ISO 3166-1 alpha-2 code for
	// Thailand.
	CountryTH Country = "TH"
	// CountryTJ is the ISO 3166-1 alpha-2 code for
	// Tajikistan.
	CountryTJ Country = "TJ"
	// CountryTK is the ISO 3166-1 alpha-2 code for
	// Tokelau.
	CountryTK Country = "TK"
	// CountryTL is the ISO 3166-1 alpha-2 code for
	// Timor-Leste.
	CountryTL Country = "TL"
	// CountryTM is the ISO 3166-1 alpha-2 code for
	// Turkmenistan.
	CountryTM Country = "TM"
	// CountryTN is the ISO 3166-1 alpha-2 code for
	// Tunisia.
	CountryTN Country = "TN"
	// CountryTO is the ISO 3166-1 alpha-2 code for
	// Tonga.
	CountryTO Country = "TO"
	// CountryTR is the ISO 3166-1 alpha-2 code for
	// Turkey.
	CountryTR Country = "TR"
	// CountryTT is the ISO 3166-1 alpha-2 code for
	// Trinidad and Tobago.
	CountryTT Country = "TT"
	// CountryTV is the ISO 3166-1 alpha-2 code for
	// Tuvalu.
	CountryTV Country = "TV"
	// CountryTW is the ISO 3166-1 alpha-2 code for
	// Taiwan, Province of China.
	CountryTW Country = "TW"
	// CountryTZ is the ISO 3166-1 alpha-2 code for
	// Tanzania, United Republic of.
	CountryTZ Country = "TZ"
	// CountryUA is the ISO 3166-1 alpha-2 code for
	// Ukraine.
	CountryUA Country = "UA"
	// CountryUG is the ISO 3166-1 alpha-2 code for
	// Uganda.
	CountryUG Country = "UG"
	// CountryUM is the ISO 3166-1 alpha-2 code for
	// United States Minor Outlying Islands.
	CountryUM Country = "UM"
	// CountryUS is the ISO 3166-1 alpha-2 code for
	// United States of America.
	CountryUS Country = "US"
	// CountryUY is the ISO 3166-1 alpha-2 code for
	// Uruguay.
	CountryUY Country = "UY"
	// CountryUZ is the ISO 3166-1 alpha-2 code for
	// Uzbekistan.
	CountryUZ Country = "UZ"
	// CountryVA is the ISO 3166-1 alpha-2 code for
	// Holy See.
	CountryVA Country = "VA"
	// CountryVC is the ISO 3166-1 alpha-2 code for
	// Saint Vincent and the Grenadines.
	CountryVC Country = "VC"
	// CountryVE is the ISO 3166-1 alpha-2 code for
	// Venezuela (Bolivarian Republic of).
	CountryVE Country = "VE"
	// CountryVG is the ISO 3166-1 alpha-2 code for
	// Virgin Islands (British).
	CountryVG Country = "VG"
	// CountryVI is the ISO 3166-1 alpha-2 code for
	// Virgin Islands (U.S.).
	CountryVI Country = "VI"
	// CountryVN is the ISO 3166-1 alpha-2 code for
	// Viet Nam.
	CountryVN Country = "VN"
	// CountryVU is the ISO 3166-1 alpha-2 code for
	// Vanuatu.
	CountryVU Country = "VU"
	// CountryWF is the ISO 3166-1 alpha-2 code for
	// Wallis and Futuna.
	CountryWF Country = "WF"
	// CountryWS is the ISO 3166-1 alpha-2 code for
	// Samoa.
	CountryWS Country = "WS"
	// CountryYE is the ISO 3166-1 alpha-2 code for
	// Yemen.
	CountryYE Country = "YE"
	// CountryYT is the ISO 3166-1 alpha-2 code for
	// Mayotte.
	CountryYT Country = "YT"
	// CountryZA is the ISO 3166-1 alpha-2 code for
	// South Africa.
	CountryZA Country = "ZA"
	// CountryZM is the ISO 3166-1 alpha-2 code for
	// Zambia.
	CountryZM Country = "ZM"
	// CountryZW is the ISO 3166-1 alpha-2 code for
	// Zimbabwe.
	CountryZW Country = "ZW"

	// CountryXK is the user-assigned ISO 3166-1 alpha-2 code for Republic of
	// Kosovo.  Kosovo does not have a recognized ISO 3166 code, but it is still
	// an entity whose user-assigned code is relatively common.
	CountryXK Country = "XK"
)

Country code constants. Note that these constants don't include the user-assigned ones.

func NewCountry

func NewCountry(s string) (c Country, err error)

NewCountry converts s into a Country while also validating it. Prefer to use this instead of a plain conversion.

func (*Country) UnmarshalText

func (c *Country) UnmarshalText(b []byte) (err error)

UnmarshalText implements the encoding.TextUnmarshaler interface for *Country.

type File

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

File is a file implementation of geoip.Interface.

func NewFile

func NewFile(c *FileConfig) (f *File, err error)

NewFile returns a new GeoIP database that reads information from a file.

func (*File) Data

func (f *File) Data(host string, ip netip.Addr) (l *Location, err error)

Data implements the Interface interface for *File. If ip is netip.Addr{}, Data tries to lookup and return the data based on host, unless it's empty.

func (*File) Refresh

func (f *File) Refresh(_ context.Context) (err error)

Refresh implements the [agdservice.Refresher] interface for *File. It reopens the GeoIP database files.

func (*File) SubnetByLocation

func (f *File) SubnetByLocation(l *Location, fam netutil.AddrFamily) (n netip.Prefix, err error)

SubnetByLocation implements the Interface interface for *File. fam must be either netutil.AddrFamilyIPv4 or netutil.AddrFamilyIPv6. l must not be nil.

The process of the subnet selection is as follows:

  1. A list of the most common ASNs, including the top ASN for each country, is pre-generated from the statistics data. See file asntops_generate.go and its output, asntops.go.

  2. During the server startup, File scans through the provided GeoIP database files searching for the fitting subnets for ASNs and countries. See resetCountrySubnets and resetTopASNSubnets.

  3. If asn is found within the list of the most used ASNs, its subnet is returned. If not, the top ASN for the provided country is chosen and its subnet is returned. If the information about the most used ASNs is not available, the first subnet from the country that is broad enough (see resetCountrySubnets) is chosen.

type FileConfig

type FileConfig struct {
	// AllTopASNs contains all subnets from CountryTopASNs.  While scanning the
	// statistics data file this list is used as a dictionary to check if the
	// current ASN included in CountryTopASNs.
	AllTopASNs map[ASN]struct{}

	// CountryTopASNs is a mapping of a country to their top ASNs.
	CountryTopASNs map[Country]ASN

	// ASNPath is the path to the GeoIP database of ASNs.
	ASNPath string

	// CountryPath is the path to the GeoIP database of countries.  The
	// databases containing subdivisions and cities info are also supported.
	CountryPath string

	// HostCacheSize is how many lookups are cached by hostname.  Zero means no
	// host caching is performed.
	HostCacheSize int

	// IPCacheSize is how many lookups are cached by IP address.
	IPCacheSize int
}

FileConfig is the file-based GeoIP configuration structure.

type Interface

type Interface interface {
	// SubnetByLocation returns the default subnet for location, if there is
	// one.  If there isn't, n is an unspecified subnet.  fam must be either
	// [netutil.AddrFamilyIPv4] or [netutil.AddrFamilyIPv6].
	SubnetByLocation(l *Location, fam netutil.AddrFamily) (n netip.Prefix, err error)

	// Data returns the GeoIP data for ip.  It may use host to get cached GeoIP
	// data if ip is netip.Addr{}.
	Data(host string, ip netip.Addr) (l *Location, err error)
}

Interface is the interface for the GeoIP database that stores the geographic data about an IP address.

type Location

type Location struct {
	// Country is the country whose subnets contain the IP address.
	Country Country

	// Continent is the continent whose subnets contain the IP address.
	Continent Continent

	// TopSubdivision is the ISO-code of the political subdivision of a country
	// whose subnets contain the IP address.  This field may be empty.
	TopSubdivision string

	// ASN is the number of the autonomous system whose subnets contain the IP
	// address.
	ASN ASN
}

Location represents the GeoIP location data about an IP address.

type NotAContinentError

type NotAContinentError struct {
	// Code is the code presented to NewContinent.
	Code string
}

NotAContinentError is returned from NewContinent when the string doesn't represent a valid continent.

func (*NotAContinentError) Error

func (err *NotAContinentError) Error() (msg string)

Error implements the error interface for *NotAContinentError.

type NotACountryError

type NotACountryError struct {
	// Code is the code presented to NewCountry.
	Code string
}

NotACountryError is returned from NewCountry when the string doesn't represent a valid country.

func (*NotACountryError) Error

func (err *NotACountryError) Error() (msg string)

Error implements the error interface for *NotACountryError.

Jump to

Keyboard shortcuts

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