修复了规则更新后没有生效的问题
This commit is contained in:
49
test_remove_rule.go
Normal file
49
test_remove_rule.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"dns-server/config"
|
||||
"dns-server/shield"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// 创建默认Shield配置
|
||||
shieldCfg := &config.ShieldConfig{
|
||||
LocalRulesFile: "data/rules.txt",
|
||||
}
|
||||
|
||||
// 创建ShieldManager
|
||||
shieldManager := shield.NewShieldManager(shieldCfg)
|
||||
|
||||
// 添加一条测试规则
|
||||
rule := "||test.example.com"
|
||||
err := shieldManager.AddRule(rule)
|
||||
if err != nil {
|
||||
log.Fatalf("添加规则失败: %v", err)
|
||||
}
|
||||
fmt.Printf("添加规则 %s 成功\n", rule)
|
||||
|
||||
// 验证规则是否被添加
|
||||
localRules := shieldManager.GetLocalRules()
|
||||
fmt.Printf("添加规则后,本地规则数量: %d\n", len(localRules["domainRules"].([]string)))
|
||||
|
||||
// 删除规则
|
||||
err = shieldManager.RemoveRule(rule + "^")
|
||||
if err != nil {
|
||||
log.Fatalf("删除规则失败: %v", err)
|
||||
}
|
||||
fmt.Printf("删除规则 %s 成功\n", rule)
|
||||
|
||||
// 验证规则是否被删除
|
||||
localRules = shieldManager.GetLocalRules()
|
||||
fmt.Printf("删除规则后,本地规则数量: %d\n", len(localRules["domainRules"].([]string)))
|
||||
|
||||
// 验证文件内容
|
||||
fileContent, err := os.ReadFile("data/rules.txt")
|
||||
if err != nil {
|
||||
log.Fatalf("读取规则文件失败: %v", err)
|
||||
}
|
||||
fmt.Printf("规则文件内容: %s\n", string(fileContent))
|
||||
}
|
||||
Reference in New Issue
Block a user