[域名解析]优化解析状态显示

This commit is contained in:
刘祥超
2020-12-23 16:49:47 +08:00
parent 0844994db8
commit df6e0a59e4
5 changed files with 138 additions and 9 deletions

View File

@@ -7,7 +7,9 @@ import (
_ "github.com/go-sql-driver/mysql"
"github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/dbs"
"github.com/iwind/TeaGo/maps"
"github.com/iwind/TeaGo/types"
"strings"
"time"
)
@@ -213,3 +215,34 @@ func (this *DNSDomainDAO) ExistAvailableDomains() (bool, error) {
Where("providerId IN (" + subQuery + ")").
Exist()
}
// 检查域名解析记录是否存在
func (this *DNSDomainDAO) ExistDomainRecord(domainId int64, recordName string, recordType string, recordRoute string, recordValue string) (bool, error) {
query := maps.Map{
"name": recordName,
"type": recordType,
}
if len(recordRoute) > 0 {
query["route"] = recordRoute
}
if len(recordValue) > 0 {
query["value"] = recordValue
// CNAME兼容点.)符号
if recordType == "CNAME" && !strings.HasSuffix(recordValue, ".") {
b, err := this.ExistDomainRecord(domainId, recordName, recordType, recordRoute, recordValue+".")
if err != nil {
return false, err
}
if b {
return true, nil
}
}
}
recordType = strings.ToUpper(recordType)
return this.Query().
Pk(domainId).
Where("JSON_CONTAINS(records, :query)").
Param("query", query.AsJSON()).
Exist()
}

View File

@@ -2,4 +2,36 @@ package models
import (
_ "github.com/go-sql-driver/mysql"
"testing"
)
func TestDNSDomainDAO_ExistDomainRecord(t *testing.T) {
{
b, err := NewDNSDomainDAO().ExistDomainRecord(1, "mycluster", "A", "", "")
if err != nil {
t.Fatal(err)
}
t.Log(b)
}
{
b, err := NewDNSDomainDAO().ExistDomainRecord(2, "mycluster", "A", "", "")
if err != nil {
t.Fatal(err)
}
t.Log(b)
}
{
b, err := NewDNSDomainDAO().ExistDomainRecord(2, "mycluster", "MX", "", "")
if err != nil {
t.Fatal(err)
}
t.Log(b)
}
{
b, err := NewDNSDomainDAO().ExistDomainRecord(2, "mycluster123", "A", "", "")
if err != nil {
t.Fatal(err)
}
t.Log(b)
}
}

View File

@@ -685,6 +685,19 @@ func (this *NodeDAO) FindAllEnabledNodesDNSWithClusterId(clusterId int64) (resul
return
}
// 计算一个集群的节点DNS数量
func (this *NodeDAO) CountAllEnabledNodesDNSWithClusterId(clusterId int64) (result int64, err error) {
return this.Query().
State(NodeStateEnabled).
Attr("clusterId", clusterId).
Attr("isOn", true).
Attr("isUp", true).
Result("id", "name", "dnsRoutes", "isOn").
DescPk().
Slice(&result).
Count()
}
// 获取单个节点的DNS信息
func (this *NodeDAO) FindEnabledNodeDNS(nodeId int64) (*Node, error) {
one, err := this.Query().