EdgeDNS支持内置线路

This commit is contained in:
GoEdgeLab
2021-08-09 13:57:58 +08:00
parent a5118536e7
commit 43fdcd3d62
9 changed files with 235 additions and 67 deletions

View File

@@ -3,10 +3,14 @@ package nameservers
import (
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
"github.com/TeaOSLab/EdgeAPI/internal/errors"
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
_ "github.com/go-sql-driver/mysql"
"github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/dbs"
"github.com/iwind/TeaGo/types"
"regexp"
"strings"
)
const (
@@ -83,6 +87,33 @@ func (this *NSRouteDAO) FindEnabledNSRoute(tx *dbs.Tx, id int64) (*NSRoute, erro
return result.(*NSRoute), err
}
// FindEnabledRouteWithCode 根据代号获取线路信息
func (this *NSRouteDAO) FindEnabledRouteWithCode(tx *dbs.Tx, code string) (*NSRoute, error) {
if regexp.MustCompile(`^id:\d+$`).MatchString(code) {
var routeId = types.Int64(code[strings.Index(code, ":")+1:])
route, err := this.FindEnabledNSRoute(tx, routeId)
if route == nil || err != nil {
return nil, err
}
route.Code = "id:" + types.String(routeId)
return route, nil
}
route := dnsconfigs.FindDefaultRoute(code)
if route == nil {
return nil, nil
}
return &NSRoute{
Id: 0,
IsOn: 1,
Name: route.Name,
Code: route.Code,
State: NSRouteStateEnabled,
}, nil
}
// FindNSRouteName 根据主键查找名称
func (this *NSRouteDAO) FindNSRouteName(tx *dbs.Tx, id int64) (string, error) {
return this.Query(tx).