Files
EdgeAPI/internal/db/models/dns_domain_model_ext.go

48 lines
1018 B
Go
Raw Normal View History

2020-11-12 14:41:28 +08:00
package models
2020-11-14 21:28:07 +08:00
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAPI/internal/dnsclients"
)
// 获取所有的线路
2020-11-15 11:57:49 +08:00
func (this *DNSDomain) DecodeRoutes() ([]*dnsclients.Route, error) {
2020-11-14 21:28:07 +08:00
if len(this.Routes) == 0 || this.Routes == "null" {
return nil, nil
}
2020-11-15 11:57:49 +08:00
result := []*dnsclients.Route{}
2020-11-14 21:28:07 +08:00
err := json.Unmarshal([]byte(this.Routes), &result)
if err != nil {
return nil, err
}
return result, nil
}
// 检查是否包含某个线路
func (this *DNSDomain) ContainsRoute(route string) (bool, error) {
routes, err := this.DecodeRoutes()
if err != nil {
return false, err
}
2020-11-15 11:57:49 +08:00
for _, r := range routes {
if r.Code == route {
return true, nil
}
}
return false, nil
2020-11-14 21:28:07 +08:00
}
// 获取所有的记录
func (this *DNSDomain) DecodeRecords() ([]*dnsclients.Record, error) {
records := this.Records
if len(records) == 0 || records == "null" {
return nil, nil
}
result := []*dnsclients.Record{}
err := json.Unmarshal([]byte(records), &result)
if err != nil {
return nil, err
}
return result, nil
}