-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgeo.go
228 lines (216 loc) · 7.39 KB
/
geo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
package lalamove
// Country ...
type Country struct {
Name string
Code CountryCode
Cities []CityCode
Locales []Locale
PhoneRegex string
}
// CityCode is the UN/LOCODE of supported cities.
type CityCode string
// CityCode enum
const (
CityCodeBrasilSaoPaulo CityCode = "BR_SAO"
CityCodeBrasilRioDeJaneiro CityCode = "BR_RIO"
CityCodeHongKongHongKong CityCode = "HK_HKG"
CityCodeIndiaBengaluru CityCode = "IN_BLR"
CityCodeIndiaMumbai CityCode = "IN_BOM"
CityCodeIndiaDelhi CityCode = "IN_DEL"
CityCodeIndonesiaJakarata CityCode = "ID_JKT"
CityCodeMalaysiaKualaLumpur CityCode = "MY_KUL"
CityCodeMexicoMexico CityCode = "MX_MEX"
CityCodePhilippinesManila CityCode = "PH_MNL"
CityCodePhilippinesCebu CityCode = "PH_CEB"
CityCodeSingaporeSingapore CityCode = "SG_SIN"
CityCodeTaiwanTaipei CityCode = "TW_TPE"
CityCodeThailandBangkok CityCode = "TH_BKK"
CityCodeThailandPattaya CityCode = "TH_PYX"
CityCodeVietnamHoChiMinh CityCode = "VN_SGN"
CityCodeVietnamHanoi CityCode = "VN_HAN"
)
// LLMCountry is the country/region/city where the order is being placed.
// 1. Hong Kong, Indonesia, Malaysia, Singapore & Taipei should be in ISO 3166-1 alpha-2 format.
// 2. Countries/regions/cities shou lbe in UN/LOCODE format.
type LLMCountry string
// GetLLMCountry ...
func (c CityCode) GetLLMCountry() LLMCountry {
switch c {
case CityCodeHongKongHongKong,
CityCodeIndonesiaJakarata,
CityCodeMalaysiaKualaLumpur,
CityCodeSingaporeSingapore,
CityCodeTaiwanTaipei:
country := c.GetCountry()
return LLMCountry(country.Code)
default:
return LLMCountry(c)
}
}
// GetCountry ...
func (c CityCode) GetCountry() Country {
switch c {
case CityCodeBrasilSaoPaulo, CityCodeBrasilRioDeJaneiro:
return CountryBrasil
case CityCodeHongKongHongKong:
return CountryHongKong
case CityCodeIndiaBengaluru, CityCodeIndiaMumbai, CityCodeIndiaDelhi:
return CountryIndia
case CityCodeIndonesiaJakarata:
return CountryIndonesia
case CityCodeMalaysiaKualaLumpur:
return CountryMalaysia
case CityCodeMexicoMexico:
return CountryMexico
case CityCodePhilippinesManila, CityCodePhilippinesCebu:
return CountryPhilippines
case CityCodeSingaporeSingapore:
return CountrySingapore
case CityCodeTaiwanTaipei:
return CountryTaiwan
case CityCodeThailandBangkok, CityCodeThailandPattaya:
return CountryThailand
case CityCodeVietnamHoChiMinh, CityCodeVietnamHanoi:
return CountryVietnam
}
return CountryUnknown
}
// CountryCode is the ISO 3166-1 alpha-2 of supported countries and regions.
type CountryCode string
// CountryCode enum
const (
CountryCodeBrasil CountryCode = "BR"
CountryCodeHongKong CountryCode = "HK"
CountryCodeIndia CountryCode = "IN"
CountryCodeIndonesia CountryCode = "ID"
CountryCodeMalaysia CountryCode = "MY"
CountryCodeMexico CountryCode = "MX"
CountryCodePhilippines CountryCode = "PH"
CountryCodeSingapore CountryCode = "SG"
CountryCodeTaiwan CountryCode = "TW"
CountryCodeThailand CountryCode = "TH"
CountryCodeVietnam CountryCode = "VN"
)
// Locale ...
type Locale string
// Locale enum
const (
LocaleBrasilEN Locale = "en_BR"
LocaleBrasilPT Locale = "pt_BR"
LocaleHongKongEN Locale = "en_HK"
LocaleHongKongZH Locale = "zh_HK"
LocaleIndiaEN Locale = "en_IN"
LocaleIndiaHI Locale = "hi_IN"
LocaleIndiaKN Locale = "kn_IN"
LocaleIndiaMR Locale = "mr_IN"
LocaleIndonesiaEN Locale = "en_ID"
LocaleIndonesiaID Locale = "id_ID"
LocaleMalaysiaEN Locale = "en_MY"
LocaleMalaysiaMS Locale = "ms_MY"
LocaleMexicoEN Locale = "en_MX"
LocaleMexicoMX Locale = "es_MX"
LocalePhilippinesEN Locale = "en_PH"
LocaleSingaporeEN Locale = "en_SG"
LocaleTaiwanZH Locale = "zh_TW"
LocaleThailandEN Locale = "en_TH"
LocaleThailandTH Locale = "th_TH"
LocaleVietnamEN Locale = "en_VN"
LocaleVietnamVI Locale = "vi_VN"
)
// Country enum
var (
CountryUnknown = Country{
Name: "Unknown",
}
CountryBrasil = Country{
Name: "Brasil",
Code: CountryCodeBrasil,
Cities: []CityCode{CityCodeBrasilSaoPaulo, CityCodeBrasilRioDeJaneiro},
PhoneRegex: "^[0-9]{2}[9]{1}[0-9]{8}$",
Locales: []Locale{LocaleBrasilEN, LocaleBrasilPT},
}
CountryHongKong = Country{
Name: "Hong Kong",
Code: CountryCodeHongKong,
Cities: []CityCode{CityCodeHongKongHongKong},
PhoneRegex: "^((?!999)([2-9][0-9]{7}))$",
Locales: []Locale{LocaleHongKongEN, LocaleHongKongZH},
}
CountryIndia = Country{
Name: "India",
Code: CountryCodeIndia,
Cities: []CityCode{CityCodeIndiaBengaluru, CityCodeIndiaMumbai, CityCodeIndiaDelhi},
PhoneRegex: "^([6-9][0-9]{9}|22[0-9]{8})$",
Locales: []Locale{LocaleIndiaEN, LocaleIndiaHI, LocaleIndiaKN, LocaleIndiaMR},
}
CountryIndonesia = Country{
Name: "Indonesia",
Code: CountryCodeIndonesia,
Cities: []CityCode{CityCodeIndonesiaJakarata},
PhoneRegex: "^0(8\\d{8,11}|21\\d{7,8})$",
Locales: []Locale{LocaleIndonesiaEN, LocaleIndonesiaID},
}
CountryMalaysia = Country{
Name: "Malaysia",
Code: CountryCodeMalaysia,
Cities: []CityCode{CityCodeMalaysiaKualaLumpur},
PhoneRegex: "^0(1[1,5]?\\d{8}|[4-7,9]\\d{7}|8[2-9]\\d{6}|3\\d{8})$",
Locales: []Locale{LocaleMalaysiaEN, LocaleMalaysiaMS},
}
CountryMexico = Country{
Name: "Mexico",
Code: CountryCodeMexico,
Cities: []CityCode{CityCodeMexicoMexico},
PhoneRegex: "^([+]+52?)?(\\d{3}?){2}\\d{4}$",
Locales: []Locale{LocaleMexicoEN, LocaleMexicoMX},
}
CountryPhilippines = Country{
Name: "Philippines",
Code: CountryCodePhilippines,
Cities: []CityCode{CityCodePhilippinesManila, CityCodePhilippinesCebu},
PhoneRegex: "^09[0-9]{9}$|^0?2[0-9]{7}$|^0?32[0-9]{7}$",
Locales: []Locale{LocalePhilippinesEN},
}
CountrySingapore = Country{
Name: "Singapore",
Code: CountryCodeSingapore,
Cities: []CityCode{CityCodeSingaporeSingapore},
PhoneRegex: "^[689]{1}[0-9]{7}$",
Locales: []Locale{LocaleSingaporeEN},
}
CountryTaiwan = Country{
Name: "Taiwan",
Code: CountryCodeTaiwan,
Cities: []CityCode{CityCodeTaiwanTaipei},
PhoneRegex: "^0([1-8]{1}[0-9]{7,8}|9[0-9]{8})$",
Locales: []Locale{LocaleTaiwanZH},
}
CountryThailand = Country{
Name: "Thailand",
Code: CountryCodeThailand,
Cities: []CityCode{CityCodeThailandBangkok, CityCodeThailandPattaya},
PhoneRegex: "^(0[0-9]{8,9}|[0-9]{4})$",
Locales: []Locale{LocaleThailandEN, LocaleThailandTH},
}
CountryVietnam = Country{
Name: "Vietnam",
Code: CountryCodeVietnam,
Cities: []CityCode{CityCodeVietnamHoChiMinh, CityCodeVietnamHanoi},
PhoneRegex: "^0?(2|[35789])[0-9]{8}$|^02[48][0-9]{8}$",
Locales: []Locale{LocaleVietnamEN, LocaleVietnamVI},
}
)
// AllCountriesByISOCode list all the countries and regions supported by Lalamove by ISO 3166-1 alpha-2 code
var AllCountriesByISOCode = map[CountryCode]Country{
CountryCodeBrasil: CountryBrasil,
CountryCodeHongKong: CountryHongKong,
CountryCodeIndia: CountryIndia,
CountryCodeIndonesia: CountryIndonesia,
CountryCodeMalaysia: CountryMalaysia,
CountryCodeMexico: CountryMexico,
CountryCodePhilippines: CountryPhilippines,
CountryCodeSingapore: CountrySingapore,
CountryCodeTaiwan: CountryTaiwan,
CountryCodeThailand: CountryThailand,
CountryCodeVietnam: CountryVietnam,
}