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

76 lines
1.8 KiB
Go
Raw Normal View History

2021-08-08 15:47:48 +08:00
package models
2022-08-22 15:11:22 +08:00
import (
"encoding/json"
2022-09-10 16:13:21 +08:00
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
2022-09-23 19:01:18 +08:00
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
2022-08-22 15:11:22 +08:00
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/ddosconfigs"
)
// DecodeDDoSProtection 解析DDOS Protection设置
func (this *NSCluster) DecodeDDoSProtection() *ddosconfigs.ProtectionConfig {
if IsNull(this.DdosProtection) {
return nil
}
var result = &ddosconfigs.ProtectionConfig{}
err := json.Unmarshal(this.DdosProtection, &result)
if err != nil {
2022-09-10 16:13:21 +08:00
remotelogs.Error("NSCluster.DecodeDDoSProtection", "decode failed: "+err.Error())
2022-08-22 15:11:22 +08:00
}
return result
}
// HasDDoSProtection 检查是否有DDOS设置
func (this *NSCluster) HasDDoSProtection() bool {
var config = this.DecodeDDoSProtection()
if config != nil {
return config.IsOn()
}
return false
2022-09-10 16:13:21 +08:00
}
// DecodeHosts 解析主机地址
func (this *NSCluster) DecodeHosts() []string {
if IsNull(this.Hosts) {
return nil
}
var hosts = []string{}
err := json.Unmarshal(this.Hosts, &hosts)
if err != nil {
remotelogs.Error("NSCluster.DecodeHosts", "decode failed: "+err.Error())
}
return hosts
}
2022-09-23 19:01:18 +08:00
2022-09-24 14:07:19 +08:00
// DecodeSOAConfig 解析SOA设置
func (this *NSCluster) DecodeSOAConfig() *dnsconfigs.NSSOAConfig {
var config = dnsconfigs.DefaultNSSOAConfig()
if IsNull(this.Soa) {
return config
}
err := json.Unmarshal(this.Soa, config)
if err != nil {
remotelogs.Error("NSCluster.DecodeSOAConfig", "decode failed: "+err.Error())
}
return config
}
2022-09-23 19:01:18 +08:00
// DecodeAnswerConfig 解析应答设置
func (this *NSCluster) DecodeAnswerConfig() *dnsconfigs.NSAnswerConfig {
var config = dnsconfigs.DefaultNSAnswerConfig()
if IsNull(this.Answer) {
return config
}
err := json.Unmarshal(this.Answer, config)
if err != nil {
remotelogs.Error("NSCluster.DecodeAnswerConfig", "decode failed: "+err.Error())
}
return config
}