增加IP级别和WAF动作相关API

This commit is contained in:
GoEdgeLab
2021-02-06 17:38:04 +08:00
parent 4a50827089
commit 8d13ee1ce9
17 changed files with 447 additions and 140 deletions

View File

@@ -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()