mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-12-10 20:20:25 +08:00
增加根据IP名单代号查找IP名单ID的接口
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/iwind/TeaGo/lists"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -31,6 +32,8 @@ var DefaultGlobalIPList = &IPList{
|
||||
IsOn: true,
|
||||
}
|
||||
|
||||
var ipListCodeRegexp = regexp.MustCompile(`^[a-zA-Z0-9_-]+$`)
|
||||
|
||||
type IPListDAO dbs.DAO
|
||||
|
||||
func NewIPListDAO() *IPListDAO {
|
||||
@@ -352,3 +355,20 @@ func (this *IPListDAO) FindServerIdWithListId(tx *dbs.Tx, listId int64) (serverI
|
||||
FindInt64Col(0)
|
||||
return
|
||||
}
|
||||
|
||||
// FindIPListIdWithCode 根据IP名单代号查找名单ID
|
||||
func (this *IPListDAO) FindIPListIdWithCode(tx *dbs.Tx, listCode string) (int64, error) {
|
||||
if len(listCode) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
return this.Query(tx).
|
||||
ResultPk().
|
||||
State(IPListStateEnabled).
|
||||
Attr("code", listCode).
|
||||
FindInt64Col(0)
|
||||
}
|
||||
|
||||
// ValidateIPListCode 校验IP名单代号格式
|
||||
func (this *IPListDAO) ValidateIPListCode(code string) bool {
|
||||
return ipListCodeRegexp.MatchString(code)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user