2020-11-04 20:54:05 +08:00
|
|
|
package iplibrary
|
|
|
|
|
|
2021-01-13 17:00:29 +08:00
|
|
|
import (
|
|
|
|
|
"github.com/iwind/TeaGo/lists"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
2020-11-04 20:54:05 +08:00
|
|
|
type Result struct {
|
|
|
|
|
CityId int64
|
|
|
|
|
Country string
|
|
|
|
|
Region string
|
|
|
|
|
Province string
|
|
|
|
|
City string
|
|
|
|
|
ISP string
|
|
|
|
|
}
|
2021-01-13 17:00:29 +08:00
|
|
|
|
|
|
|
|
func (this *Result) Summary() string {
|
|
|
|
|
pieces := []string{}
|
|
|
|
|
if len(this.Country) > 0 {
|
|
|
|
|
pieces = append(pieces, this.Country)
|
|
|
|
|
}
|
|
|
|
|
if len(this.Province) > 0 && !lists.ContainsString(pieces, this.Province) {
|
|
|
|
|
pieces = append(pieces, this.Province)
|
|
|
|
|
}
|
|
|
|
|
if len(this.City) > 0 && !lists.ContainsString(pieces, this.City) && !lists.ContainsString(pieces, strings.TrimSuffix(this.Province, "市")) {
|
|
|
|
|
pieces = append(pieces, this.City)
|
|
|
|
|
}
|
|
|
|
|
return strings.Join(pieces, " ")
|
|
|
|
|
}
|