mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-14 16:30:26 +08:00
增加IP级别和WAF动作相关API
This commit is contained in:
@@ -15,6 +15,8 @@ const (
|
||||
IPListStateDisabled = 0 // 已禁用
|
||||
)
|
||||
|
||||
var listTypeCacheMap = map[int64]string{} // listId => type
|
||||
|
||||
type IPListDAO dbs.DAO
|
||||
|
||||
func NewIPListDAO() *IPListDAO {
|
||||
@@ -74,6 +76,36 @@ func (this *IPListDAO) FindIPListName(tx *dbs.Tx, id int64) (string, error) {
|
||||
FindStringCol("")
|
||||
}
|
||||
|
||||
// 获取名单类型
|
||||
func (this *IPListDAO) FindIPListTypeCacheable(tx *dbs.Tx, listId int64) (string, error) {
|
||||
// 检查缓存
|
||||
SharedCacheLocker.RLock()
|
||||
listType, ok := listTypeCacheMap[listId]
|
||||
SharedCacheLocker.RUnlock()
|
||||
if ok {
|
||||
return listType, nil
|
||||
}
|
||||
|
||||
listType, err := this.Query(tx).
|
||||
Pk(listId).
|
||||
Result("type").
|
||||
FindStringCol("")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if len(listType) == 0 {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
// 保存缓存
|
||||
SharedCacheLocker.Lock()
|
||||
listTypeCacheMap[listId] = listType
|
||||
SharedCacheLocker.Unlock()
|
||||
|
||||
return listType, nil
|
||||
}
|
||||
|
||||
// 创建名单
|
||||
func (this *IPListDAO) CreateIPList(tx *dbs.Tx, userId int64, listType ipconfigs.IPListType, name string, code string, timeoutJSON []byte) (int64, error) {
|
||||
op := NewIPListOperator()
|
||||
|
||||
Reference in New Issue
Block a user