IP库增加多个辅助查询函数

This commit is contained in:
刘祥超
2023-08-24 12:21:26 +08:00
parent 6a42827ebd
commit f056a9c5bd
3 changed files with 74 additions and 0 deletions
+27
View File
@@ -183,6 +183,33 @@ func (this *QueryResult) Summary() string {
return strings.Join(pieces, " ")
}
func (this *QueryResult) RegionSummary() string {
if this.item == nil {
return ""
}
var pieces = []string{}
var countryName = this.CountryName()
var provinceName = this.ProvinceName()
var cityName = this.CityName()
var townName = this.TownName()
if len(countryName) > 0 {
pieces = append(pieces, countryName)
}
if len(provinceName) > 0 && !lists.ContainsString(pieces, provinceName) {
pieces = append(pieces, provinceName)
}
if len(cityName) > 0 && !lists.ContainsString(pieces, cityName) && !lists.ContainsString(pieces, strings.TrimSuffix(cityName, "市")) {
pieces = append(pieces, cityName)
}
if len(townName) > 0 && !lists.ContainsString(pieces, townName) && !lists.ContainsString(pieces, strings.TrimSuffix(townName, "县")) {
pieces = append(pieces, townName)
}
return strings.Join(pieces, " ")
}
func (this *QueryResult) realCountryId() uint16 {
if this.item != nil {
switch item := this.item.(type) {