mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2026-01-07 07:55:48 +08:00
支持阿里云DNS
This commit is contained in:
@@ -2,6 +2,7 @@ package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/dnsclients"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
@@ -162,7 +163,7 @@ func (this *DNSDomainDAO) UpdateDomainRoutes(domainId int64, routesJSON []byte)
|
||||
}
|
||||
|
||||
// 查找域名线路
|
||||
func (this *DNSDomainDAO) FindDomainRoutes(domainId int64) ([]string, error) {
|
||||
func (this *DNSDomainDAO) FindDomainRoutes(domainId int64) ([]*dnsclients.Route, error) {
|
||||
routes, err := this.Query().
|
||||
Pk(domainId).
|
||||
Result("routes").
|
||||
@@ -173,10 +174,24 @@ func (this *DNSDomainDAO) FindDomainRoutes(domainId int64) ([]string, error) {
|
||||
if len(routes) == 0 || routes == "null" {
|
||||
return nil, nil
|
||||
}
|
||||
result := []string{}
|
||||
result := []*dnsclients.Route{}
|
||||
err = json.Unmarshal([]byte(routes), &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// 查找线路名称
|
||||
func (this *DNSDomainDAO) FindDomainRouteName(domainId int64, routeCode string) (string, error) {
|
||||
routes, err := this.FindDomainRoutes(domainId)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
for _, route := range routes {
|
||||
if route.Code == routeCode {
|
||||
return route.Name, nil
|
||||
}
|
||||
}
|
||||
return "", nil
|
||||
}
|
||||
|
||||
@@ -3,15 +3,14 @@ package models
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/dnsclients"
|
||||
"github.com/iwind/TeaGo/lists"
|
||||
)
|
||||
|
||||
// 获取所有的线路
|
||||
func (this *DNSDomain) DecodeRoutes() ([]string, error) {
|
||||
func (this *DNSDomain) DecodeRoutes() ([]*dnsclients.Route, error) {
|
||||
if len(this.Routes) == 0 || this.Routes == "null" {
|
||||
return nil, nil
|
||||
}
|
||||
result := []string{}
|
||||
result := []*dnsclients.Route{}
|
||||
err := json.Unmarshal([]byte(this.Routes), &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -25,7 +24,12 @@ func (this *DNSDomain) ContainsRoute(route string) (bool, error) {
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return lists.ContainsString(routes, route), nil
|
||||
for _, r := range routes {
|
||||
if r.Code == route {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// 获取所有的记录
|
||||
|
||||
Reference in New Issue
Block a user