优化代码

This commit is contained in:
GoEdgeLab
2022-04-19 12:58:00 +08:00
parent f5a40b6956
commit 682240a202
4 changed files with 24 additions and 22 deletions

1
internal/dnsclients/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*_plus_test.go

View File

@@ -279,15 +279,15 @@ func (this *CloudFlareProvider) doAPI(method string, apiPath string, args map[st
return errors.New("invalid response status '" + strconv.Itoa(resp.StatusCode) + "', response '" + string(data) + "'")
}
err = json.Unmarshal(data, respPtr)
if err != nil {
return err
}
if resp.StatusCode != http.StatusOK {
return errors.New("response error: " + string(data))
}
err = json.Unmarshal(data, respPtr)
if err != nil {
return errors.New("decode json failed: " + err.Error() + ", response text: " + string(data))
}
return nil
}

View File

@@ -1,7 +1,6 @@
package dnsclients
import (
teaconst "github.com/TeaOSLab/EdgeAPI/internal/const"
"github.com/iwind/TeaGo/maps"
)
@@ -49,21 +48,7 @@ func FindAllProviderTypes() []maps.Map {
},
}
if teaconst.IsPlus {
typeMaps = append(typeMaps, []maps.Map{
{
"name": "EdgeDNS",
"code": ProviderTypeLocalEdgeDNS,
"description": "GoEdge商业版提供的智能DNS服务。",
},
// TODO 需要实现用户使用AccessId/AccessKey来连接DNS服务
/**{
"name": "用户EdgeDNS",
"code": ProviderTypeUserEdgeDNS,
"description": "通过API连接企业版提供的DNS服务。",
},**/
}...)
}
typeMaps = filterTypeMaps(typeMaps)
typeMaps = append(typeMaps, maps.Map{
"name": "自定义HTTP DNS",
@@ -91,7 +76,8 @@ func FindProvider(providerType ProviderType) ProviderInterface {
case ProviderTypeCustomHTTP:
return &CustomHTTPProvider{}
}
return nil
return filterProvider(providerType)
}
// FindProviderTypeName 查找服务商名称

View File

@@ -0,0 +1,15 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
//go:build !plus
// +build !plus
package dnsclients
import "github.com/iwind/TeaGo/maps"
func filterTypeMaps(typeMaps []maps.Map) []maps.Map {
return typeMaps
}
func filterProvider(providerType string) ProviderInterface {
return nil
}