Browse Source

Lookup continent matches before using the global name

Closes #1
Ask Bjørn Hansen 13 years ago
parent
commit
7da786961d
2 changed files with 259 additions and 2 deletions
  1. 253 0
      countries/countries.go
  2. 6 2
      types.go

+ 253 - 0
countries/countries.go

@@ -0,0 +1,253 @@
+package countries
+
+var CountryContinent = map[string]string{
+	"ad": "europe",
+	"ae": "asia",
+	"af": "asia",
+	"ag": "north-america",
+	"ai": "north-america",
+	"al": "europe",
+	"am": "asia",
+	"an": "north-america",
+	"ao": "africa",
+	"ap": "asia",
+	"aq": "antarctica",
+	"ar": "south-america",
+	"as": "oceania",
+	"at": "europe",
+	"au": "oceania",
+	"aw": "north-america",
+	"ax": "europe",
+	"az": "asia",
+	"ba": "europe",
+	"bb": "north-america",
+	"bd": "asia",
+	"be": "europe",
+	"bf": "africa",
+	"bg": "europe",
+	"bh": "asia",
+	"bi": "africa",
+	"bj": "africa",
+	"bl": "north-america",
+	"bm": "north-america",
+	"bn": "asia",
+	"bo": "south-america",
+	"br": "south-america",
+	"bs": "north-america",
+	"bt": "asia",
+	"bv": "antarctica",
+	"bw": "africa",
+	"by": "europe",
+	"bz": "north-america",
+	"ca": "north-america",
+	"cc": "asia",
+	"cd": "africa",
+	"cf": "africa",
+	"cg": "africa",
+	"ch": "europe",
+	"ci": "africa",
+	"ck": "oceania",
+	"cl": "south-america",
+	"cm": "africa",
+	"cn": "asia",
+	"co": "south-america",
+	"cr": "north-america",
+	"cu": "north-america",
+	"cv": "africa",
+	"cx": "asia",
+	"cy": "asia",
+	"cz": "europe",
+	"de": "europe",
+	"dj": "africa",
+	"dk": "europe",
+	"dm": "north-america",
+	"do": "north-america",
+	"dz": "africa",
+	"ec": "south-america",
+	"ee": "europe",
+	"eg": "africa",
+	"eh": "africa",
+	"er": "africa",
+	"es": "europe",
+	"et": "africa",
+	"eu": "europe",
+	"fi": "europe",
+	"fj": "oceania",
+	"fk": "south-america",
+	"fm": "oceania",
+	"fo": "europe",
+	"fr": "europe",
+	"fx": "europe",
+	"ga": "africa",
+	"gb": "europe",
+	"gd": "north-america",
+	"ge": "asia",
+	"gf": "south-america",
+	"gg": "europe",
+	"gh": "africa",
+	"gi": "europe",
+	"gl": "north-america",
+	"gm": "africa",
+	"gn": "africa",
+	"gp": "north-america",
+	"gq": "africa",
+	"gr": "europe",
+	"gs": "antarctica",
+	"gt": "north-america",
+	"gu": "oceania",
+	"gw": "africa",
+	"gy": "south-america",
+	"hk": "asia",
+	"hm": "antarctica",
+	"hn": "north-america",
+	"hr": "europe",
+	"ht": "north-america",
+	"hu": "europe",
+	"id": "asia",
+	"ie": "europe",
+	"il": "asia",
+	"im": "europe",
+	"in": "asia",
+	"io": "asia",
+	"iq": "asia",
+	"ir": "asia",
+	"is": "europe",
+	"it": "europe",
+	"je": "europe",
+	"jm": "north-america",
+	"jo": "asia",
+	"jp": "asia",
+	"ke": "africa",
+	"kg": "asia",
+	"kh": "asia",
+	"ki": "oceania",
+	"km": "africa",
+	"kn": "north-america",
+	"kp": "asia",
+	"kr": "asia",
+	"kw": "asia",
+	"ky": "north-america",
+	"kz": "asia",
+	"la": "asia",
+	"lb": "asia",
+	"lc": "north-america",
+	"li": "europe",
+	"lk": "asia",
+	"lr": "africa",
+	"ls": "africa",
+	"lt": "europe",
+	"lu": "europe",
+	"lv": "europe",
+	"ly": "africa",
+	"ma": "africa",
+	"mc": "europe",
+	"md": "europe",
+	"me": "europe",
+	"mf": "north-america",
+	"mg": "africa",
+	"mh": "oceania",
+	"mk": "europe",
+	"ml": "africa",
+	"mm": "asia",
+	"mn": "asia",
+	"mo": "asia",
+	"mp": "oceania",
+	"mq": "north-america",
+	"mr": "africa",
+	"ms": "north-america",
+	"mt": "europe",
+	"mu": "africa",
+	"mv": "asia",
+	"mw": "africa",
+	"mx": "north-america",
+	"my": "asia",
+	"mz": "africa",
+	"na": "africa",
+	"nc": "oceania",
+	"ne": "africa",
+	"nf": "oceania",
+	"ng": "africa",
+	"ni": "north-america",
+	"nl": "europe",
+	"no": "europe",
+	"np": "asia",
+	"nr": "oceania",
+	"nu": "oceania",
+	"nz": "oceania",
+	"om": "asia",
+	"pa": "north-america",
+	"pe": "south-america",
+	"pf": "oceania",
+	"pg": "oceania",
+	"ph": "asia",
+	"pk": "asia",
+	"pl": "europe",
+	"pm": "north-america",
+	"pn": "oceania",
+	"pr": "north-america",
+	"ps": "asia",
+	"pt": "europe",
+	"pw": "oceania",
+	"py": "south-america",
+	"qa": "asia",
+	"re": "africa",
+	"ro": "europe",
+	"rs": "europe",
+	"ru": "europe",
+	"rw": "africa",
+	"sa": "asia",
+	"sb": "oceania",
+	"sc": "africa",
+	"sd": "africa",
+	"se": "europe",
+	"sg": "asia",
+	"sh": "africa",
+	"si": "europe",
+	"sj": "europe",
+	"sk": "europe",
+	"sl": "africa",
+	"sm": "europe",
+	"sn": "africa",
+	"so": "africa",
+	"sr": "south-america",
+	"st": "africa",
+	"sv": "north-america",
+	"sy": "asia",
+	"sz": "africa",
+	"tc": "north-america",
+	"td": "africa",
+	"tf": "antarctica",
+	"tg": "africa",
+	"th": "asia",
+	"tj": "asia",
+	"tk": "oceania",
+	"tl": "asia",
+	"tm": "asia",
+	"tn": "africa",
+	"to": "oceania",
+	"tr": "europe",
+	"tt": "north-america",
+	"tv": "oceania",
+	"tw": "asia",
+	"tz": "africa",
+	"ua": "europe",
+	"ug": "africa",
+	"um": "oceania",
+	"us": "north-america",
+	"uy": "south-america",
+	"uz": "asia",
+	"va": "europe",
+	"vc": "north-america",
+	"ve": "south-america",
+	"vg": "north-america",
+	"vi": "north-america",
+	"vn": "asia",
+	"vu": "oceania",
+	"wf": "oceania",
+	"ws": "oceania",
+	"ye": "asia",
+	"yt": "africa",
+	"za": "africa",
+	"zm": "africa",
+	"zw": "africa",
+}

+ 6 - 2
types.go

@@ -1,6 +1,7 @@
 package main
 package main
 
 
 import (
 import (
+	"geodns/countries"
 	"github.com/miekg/dns"
 	"github.com/miekg/dns"
 )
 )
 
 
@@ -60,12 +61,15 @@ func (z *Zone) findLabels(s, cc string, qtype uint16) *Label {
 	selectors := []string{}
 	selectors := []string{}
 
 
 	if len(cc) > 0 {
 	if len(cc) > 0 {
+		continent := countries.CountryContinent[cc]
 		if len(s) > 0 {
 		if len(s) > 0 {
 			cc = s + "." + cc
 			cc = s + "." + cc
+			if len(continent) > 0 {
+				continent = s + "." + continent
+			}
 		}
 		}
-		selectors = append(selectors, cc)
+		selectors = append(selectors, cc, continent)
 	}
 	}
-	// TODO(ask) Add continent, see https://github.com/abh/geodns/issues/1
 	selectors = append(selectors, s)
 	selectors = append(selectors, s)
 
 
 	for _, name := range selectors {
 	for _, name := range selectors {