Documentation
¶
Overview ¶
Code generated by internal/cmd/gencountries from data/countries.json. DO NOT EDIT.
Code generated by internal/cmd/genregions from data/regions.json. DO NOT EDIT.
Index ¶
- Constants
- Variables
- type Continent
- type Coordinates
- type Country
- func (c *Country) Code3() string
- func (c *Country) Continent() string
- func (c *Country) Currency() []string
- func (c *Country) ISO2() string
- func (c *Country) ISO3() string
- func (c *Country) Languages() []string
- func (c Country) MarshalJSON() ([]byte, error)
- func (c *Country) NearestRegion(lat, lng float32) *Region
- func (c *Country) Phones() []string
- func (c *Country) Regions() []Region
- func (c *Country) TimeZones() []TimeZone
- type CountryCode2
- func (cc CountryCode2) ID() uint8
- func (cc CountryCode2) ISO2() string
- func (cc CountryCode2) ISO3() string
- func (cc CountryCode2) MarshalJSON() ([]byte, error)
- func (cc CountryCode2) Object() *Country
- func (cc *CountryCode2) Scan(data interface{}) error
- func (cc CountryCode2) String() string
- func (cc *CountryCode2) UnmarshalJSON(data []byte) error
- func (cc CountryCode2) Value() (driver.Value, error)
- type CountryID
- func (id CountryID) Code() CountryCode2
- func (id CountryID) ID() uint8
- func (id CountryID) ISO2() string
- func (id CountryID) ISO3() string
- func (id CountryID) MarshalJSON() ([]byte, error)
- func (id CountryID) Object() *Country
- func (id *CountryID) Scan(data interface{}) error
- func (id CountryID) String() string
- func (id *CountryID) UnmarshalJSON(data []byte) error
- func (id CountryID) Value() (driver.Value, error)
- type Region
- type RegionCode
- func (rc RegionCode) Country() CountryCode2
- func (rc RegionCode) ISO3166() string
- func (rc RegionCode) MarshalJSON() ([]byte, error)
- func (rc RegionCode) Region() *Region
- func (rc *RegionCode) Scan(data interface{}) error
- func (rc RegionCode) String() string
- func (rc *RegionCode) UnmarshalJSON(data []byte) error
- func (rc RegionCode) Value() (driver.Value, error)
- type TimeZone
Constants ¶
const ( UndefinedCountryCodeISO2 = "**" UndefinedCountryCodeISO3 = "***" )
undefined country codes
const UndefinedRegionISO3166 = "**-**"
Undefined ISO 3166-2 code.
Variables ¶
var ( ErrCode2InvalidScanType = errors.New("[gogeo.code2] invalid scan type, supports only bytes and string") ErrCode2InvalidValueSize = errors.New("[gogeo.code2] invalid value size, supports only two 2 chars") )
Error list...
var ( ErrCountryIDInvalidScanType = errors.New("[gogeo.countryid] invalid scan type, supports only bytes and string") ErrCountryIDInvalidValueSize = errors.New("[gogeo.countryid] invalid value size, supports only two 2 chars") )
Error list for CountryID SQL scanning.
var Continents = []Continent{
{ID: 1, Code2: "EU", Name: "Europe"},
{ID: 2, Code2: "AS", Name: "Asia"},
{ID: 3, Code2: "AF", Name: "Africa"},
{ID: 4, Code2: "OC", Name: "Oceania"},
{ID: 5, Code2: "SA", Name: "South America"},
{ID: 6, Code2: "NA", Name: "North America"},
{ID: 7, Code2: "AN", Name: "Antarctica"},
}
Continents list (IDs are 1-based; Country.continent stores this ID).
var Countries = countries[:]
Countries is the public list of all countries. Index equals Country.ID.
var (
ErrRegionCodeInvalidScanType = errors.New("[gogeo.region] invalid scan type, supports only bytes and string")
)
Error list for RegionCode SQL scanning.
var Regions = regions[:]
Regions is the public list of all subdivisions. Index equals Region.ID.
var UndefinedCountryCode2 = CountryCode2{UndefinedCountryCodeISO2[0], UndefinedCountryCodeISO2[1]}
UndefinedCountryCode2 for undefined codename
var UndefinedRegionCode = RegionCode(0)
UndefinedRegionCode is the sentinel ISO 3166-2 code.
Functions ¶
This section is empty.
Types ¶
type Continent ¶
Continent description
func ContinentByCode2 ¶
ContinentByCode2 returns a continent by ISO-like 2-letter code, or nil.
type Country ¶
type Country struct {
ID uint8
Code2 CountryCode2
Name string
Native string
Capital string
Coordinates Coordinates
AvgUTCOffset int16
// contains filtered or unexported fields
}
Country is a compact country record. Variable-length lists are stored in package-level packed tables and exposed via methods.
func CountryByCode2 ¶
CountryByCode2 returns the country for an ISO-2 code. Unknown codes resolve to the undefined country (never nil).
func CountryByCode2Bytes ¶
func CountryByCode2Bytes(code CountryCode2) *Country
CountryByCode2Bytes is the allocation-free ISO-2 lookup. Unknown codes resolve to the undefined country (never nil).
func CountryByCode3 ¶
CountryByCode3 returns the country for an ISO-3 code. Empty and unknown codes resolve to the undefined country (never nil).
func CountryByID ¶
CountryByID returns the country with the given ID, or the undefined country.
func (*Country) ISO3 ¶
ISO3 returns the interned ISO-3166 alpha-3 code (empty if the entry has none).
func (Country) MarshalJSON ¶
MarshalJSON encodes Country using the historical field names.
func (*Country) NearestRegion ¶
NearestRegion returns the nearest subdivision of this country, or undefined.
type CountryCode2 ¶ added in v1.1.0
type CountryCode2 [2]byte
CountryCode2 implements a 2-letter country code.
func CountryCode2ByString ¶
func CountryCode2ByString(code string) CountryCode2
CountryCode2ByString returns code by string code ISO-2 or ISO-3.
func (CountryCode2) ID ¶ added in v1.1.1
func (cc CountryCode2) ID() uint8
ID returns the interned country code, or 0 for undefined.
func (CountryCode2) ISO2 ¶ added in v1.1.0
func (cc CountryCode2) ISO2() string
ISO2 returns the interned two-letter code for a known country, or "**". Aliases resolve to the canonical code (UK → GB).
func (CountryCode2) ISO3 ¶ added in v1.1.0
func (cc CountryCode2) ISO3() string
ISO3 returns the interned three-letter code for the matching country.
func (CountryCode2) MarshalJSON ¶ added in v1.1.0
func (cc CountryCode2) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler interface
func (CountryCode2) Object ¶ added in v1.2.0
func (cc CountryCode2) Object() *Country
Object returns the country for this code, or the undefined country. UK resolves to GB. Never nil.
func (*CountryCode2) Scan ¶ added in v1.1.0
func (cc *CountryCode2) Scan(data interface{}) error
Scan implementation of sql.Scanner interface
func (CountryCode2) String ¶ added in v1.1.0
func (cc CountryCode2) String() string
func (*CountryCode2) UnmarshalJSON ¶ added in v1.1.0
func (cc *CountryCode2) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler interface
type CountryID ¶ added in v1.3.0
type CountryID uint8
CountryID is a country index for JSON and SQL fields. On the wire it is the ISO-2 code, same as CountryCode2.
var UndefinedCountryID CountryID
UndefinedCountryID is the sentinel country index.
func CountryIDByString ¶ added in v1.3.0
CountryIDByString parses an ISO-2 or ISO-3 code. Unknown values become undefined.
func (CountryID) Code ¶ added in v1.3.0
func (id CountryID) Code() CountryCode2
Code returns the canonical ISO-2 code. UK resolves to GB.
func (CountryID) ISO3 ¶ added in v1.3.0
ISO3 returns the interned three-letter code for the matching country.
func (CountryID) MarshalJSON ¶ added in v1.3.0
MarshalJSON implements json.Marshaler.
func (CountryID) Object ¶ added in v1.3.0
Object returns the country for this index, or the undefined country. Never nil.
func (*CountryID) UnmarshalJSON ¶ added in v1.3.0
UnmarshalJSON implements json.Unmarshaler.
type Region ¶
type Region struct {
ID uint16
Name string
Coordinates Coordinates
UTCOffset int16
// contains filtered or unexported fields
}
Region is a compact ISO 3166-2 subdivision record.
func RegionByCode ¶
RegionByCode returns the region for an ISO 3166-2 code (for example "US-CA"). Hyphenated and compact forms are equivalent ("NL-ZH" and "NLZH"). "GB-*" and "UK-*" resolve to the same United Kingdom subdivisions (country code GB). Unknown codes resolve to the undefined region (never nil).
func RegionByID ¶
RegionByID returns the region with the given ID, or the undefined region.
func RegionByLatLng ¶
RegionByLatLng returns the nearest region with coordinates, or undefined.
func (*Region) Country ¶
Country returns the parent country. GB subdivisions resolve to GB. Never nil.
func (*Region) HasCoordinates ¶
HasCoordinates reports whether the region has a known centroid.
func (*Region) RegionCode ¶
func (r *Region) RegionCode() RegionCode
RegionCode returns the JSON/SQL code wrapper for this region.
type RegionCode ¶
type RegionCode uint16
RegionCode is an ISO 3166-2 subdivision code for JSON and SQL fields.
func RegionCodeByString ¶
func RegionCodeByString(code string) RegionCode
RegionCodeByString parses an ISO 3166-2 code. Unknown values become undefined.
func (RegionCode) Country ¶
func (rc RegionCode) Country() CountryCode2
Country returns the library country code (GB subdivisions → GB).
func (RegionCode) ISO3166 ¶
func (rc RegionCode) ISO3166() string
ISO3166 returns the interned ISO 3166-2 code, or "**-**".
func (RegionCode) MarshalJSON ¶
func (rc RegionCode) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (RegionCode) Region ¶
func (rc RegionCode) Region() *Region
Region returns the matching region (never nil).
func (*RegionCode) Scan ¶
func (rc *RegionCode) Scan(data interface{}) error
Scan implementation of sql.Scanner.
func (RegionCode) String ¶
func (rc RegionCode) String() string
func (*RegionCode) UnmarshalJSON ¶
func (rc *RegionCode) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
cmd/export
command
Command export dumps gogeo countries or ISO 3166-2 regions as JSON or CSV.
|
Command export dumps gogeo countries or ISO 3166-2 regions as JSON or CSV. |
|
cmd/gencountries
command
Command gencountries builds packed country tables from data/countries.json.
|
Command gencountries builds packed country tables from data/countries.json. |
|
cmd/genregions
command
Command genregions builds packed ISO 3166-2 tables from data/regions.json.
|
Command genregions builds packed ISO 3166-2 tables from data/regions.json. |
|
cmd/mergerregions
command
Command mergerregions merges Debian iso-codes and oodavid/iso-3166-2 into data/regions.json.
|
Command mergerregions merges Debian iso-codes and oodavid/iso-3166-2 into data/regions.json. |
|
utcoffset
Package utcoffset resolves a stable standard-time UTC offset for an IANA zone.
|
Package utcoffset resolves a stable standard-time UTC offset for an IANA zone. |