Files
EdgeAPI/internal/dnsclients/types.go

57 lines
1.1 KiB
Go
Raw Normal View History

package dnsclients
2020-11-11 21:32:25 +08:00
import "github.com/iwind/TeaGo/maps"
type ProviderType = string
2020-11-12 14:41:28 +08:00
// 服务商代号
2020-11-11 21:32:25 +08:00
const (
2021-01-28 11:29:57 +08:00
ProviderTypeDNSPod ProviderType = "dnspod"
ProviderTypeAliDNS ProviderType = "alidns"
ProviderTypeDNSCom ProviderType = "dnscom"
ProviderTypeCustomHTTP ProviderType = "customHTTP"
2020-11-11 21:32:25 +08:00
)
2020-11-12 14:41:28 +08:00
// 所有的服务商类型
2020-11-11 21:32:25 +08:00
var AllProviderTypes = []maps.Map{
{
2020-11-15 11:57:49 +08:00
"name": "阿里云DNS",
"code": ProviderTypeAliDNS,
2020-11-11 21:32:25 +08:00
},
2020-11-12 14:41:28 +08:00
{
2020-11-15 11:57:49 +08:00
"name": "DNSPod",
"code": ProviderTypeDNSPod,
2020-11-12 14:41:28 +08:00
},
2020-11-15 11:57:49 +08:00
/**{
"name": "帝恩思DNS.COM",
2020-11-12 14:41:28 +08:00
"code": ProviderTypeDNSCom,
2020-11-15 11:57:49 +08:00
},**/
2021-01-28 11:29:57 +08:00
{
"name": "自定义HTTP DNS",
"code": ProviderTypeCustomHTTP,
},
2020-11-11 21:32:25 +08:00
}
// 查找服务商实例
func FindProvider(providerType ProviderType) ProviderInterface {
switch providerType {
case ProviderTypeDNSPod:
return &DNSPodProvider{}
2020-11-15 11:57:49 +08:00
case ProviderTypeAliDNS:
return &AliDNSProvider{}
2021-01-28 11:29:57 +08:00
case ProviderTypeCustomHTTP:
return &CustomHTTPProvider{}
}
return nil
}
// 查找服务商名称
func FindProviderTypeName(providerType ProviderType) string {
2020-11-11 21:32:25 +08:00
for _, t := range AllProviderTypes {
if t.GetString("code") == providerType {
return t.GetString("name")
}
}
return ""
}