2021-01-25 16:40:03 +08:00
|
|
|
package regions
|
2022-01-06 16:25:23 +08:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
2022-08-13 23:55:48 +08:00
|
|
|
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
|
|
|
|
"github.com/iwind/TeaGo/lists"
|
2022-01-06 16:25:23 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func (this *RegionCity) DecodeCodes() []string {
|
|
|
|
|
if len(this.Codes) == 0 {
|
|
|
|
|
return []string{}
|
|
|
|
|
}
|
2022-08-13 23:55:48 +08:00
|
|
|
var result = []string{}
|
2022-03-22 19:30:30 +08:00
|
|
|
err := json.Unmarshal(this.Codes, &result)
|
2022-01-06 16:25:23 +08:00
|
|
|
if err != nil {
|
2022-08-13 23:55:48 +08:00
|
|
|
remotelogs.Error("RegionCity.DecodeCodes", err.Error())
|
2022-01-06 16:25:23 +08:00
|
|
|
}
|
|
|
|
|
return result
|
|
|
|
|
}
|
2022-08-13 23:55:48 +08:00
|
|
|
|
|
|
|
|
func (this *RegionCity) DecodeCustomCodes() []string {
|
|
|
|
|
if len(this.CustomCodes) == 0 {
|
|
|
|
|
return []string{}
|
|
|
|
|
}
|
|
|
|
|
var result = []string{}
|
|
|
|
|
err := json.Unmarshal(this.CustomCodes, &result)
|
|
|
|
|
if err != nil {
|
|
|
|
|
remotelogs.Error("RegionCity.DecodeCustomCodes", err.Error())
|
|
|
|
|
}
|
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *RegionCity) DisplayName() string {
|
|
|
|
|
if len(this.CustomName) > 0 {
|
|
|
|
|
return this.CustomName
|
|
|
|
|
}
|
|
|
|
|
return this.Name
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *RegionCity) AllCodes() []string {
|
|
|
|
|
var codes = this.DecodeCodes()
|
|
|
|
|
|
|
|
|
|
if len(this.Name) > 0 && !lists.ContainsString(codes, this.Name) {
|
|
|
|
|
codes = append(codes, this.Name)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(this.CustomName) > 0 && !lists.ContainsString(codes, this.CustomName) {
|
|
|
|
|
codes = append(codes, this.CustomName)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, code := range this.DecodeCustomCodes() {
|
|
|
|
|
if !lists.ContainsString(codes, code) {
|
|
|
|
|
codes = append(codes, code)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return codes
|
|
|
|
|
}
|