refactor(resolver,variable): 移除未使用的接口和测试代码

- resolver: 移除 StatsCollector 接口和 mockResolver 测试代码
- variable: 移除 Store 接口定义

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
xfy 2026-04-14 15:56:29 +08:00
parent 6866c763f1
commit 11956a0f83
3 changed files with 0 additions and 77 deletions

View File

@ -14,46 +14,6 @@ import (
"rua.plus/lolly/internal/config"
)
// mockResolver 是一个模拟的 Resolver 实现,用于基准测试。
// 它返回固定的 IP 地址,避免网络依赖,确保测试的稳定性和可重复性。
type mockResolver struct {
ips []string
delay time.Duration
}
// LookupHost 模拟解析主机名,返回固定的 IP 地址列表。
func (m *mockResolver) LookupHost(ctx context.Context, host string) ([]string, error) {
if m.delay > 0 {
time.Sleep(m.delay)
}
return m.ips, nil
}
// LookupHostWithCache 带缓存的解析实现。
func (m *mockResolver) LookupHostWithCache(ctx context.Context, host string) ([]string, error) {
return m.LookupHost(ctx, host)
}
// Refresh 刷新指定主机的缓存(模拟实现)。
func (m *mockResolver) Refresh(host string) error {
return nil
}
// Start 启动后台刷新协程(模拟实现)。
func (m *mockResolver) Start() error {
return nil
}
// Stop 停止解析器(模拟实现)。
func (m *mockResolver) Stop() error {
return nil
}
// Stats 返回统计信息(模拟实现)。
func (m *mockResolver) Stats() Stats {
return Stats{}
}
// createTestResolver 创建一个用于基准测试的 DNSResolver 实例。
// 预填充缓存以模拟真实场景。
func createTestResolver() *DNSResolver {

View File

@ -22,35 +22,6 @@ import (
"time"
)
// StatsCollector 定义 DNS 解析器统计收集器的接口。
//
// 该接口用于抽象统计数据的收集和查询操作,支持:
// - 记录缓存命中和未命中事件
// - 记录解析错误
// - 记录解析延迟
// - 获取汇总统计数据
//
// 实现要求:
// - 所有方法必须是并发安全的
// - 统计数据的更新应使用原子操作
// - GetStats 返回的数据应反映当前时刻的快照
//
// 使用场景:
//
// 通常由 DNSResolver 实现此接口,供监控系统或管理接口调用。
type StatsCollector interface {
// RecordHit 记录缓存命中
RecordHit()
// RecordMiss 记录缓存未命中
RecordMiss()
// RecordError 记录解析错误
RecordError()
// RecordLatency 记录解析延迟
RecordLatency(latency time.Duration)
// GetStats 获取当前统计
GetStats() Stats
}
// ResetStats 重置所有统计信息为初始值。
//
// 将缓存命中次数、缓存未命中次数、解析错误次数、

View File

@ -26,14 +26,6 @@ import (
"github.com/valyala/fasthttp"
)
// Store 变量存储接口
type Store interface {
// Get 获取变量值
Get(name string) (string, bool)
// Set 设置变量值(用于自定义变量)
Set(name string, value string)
}
// BuiltinVariable 内置变量定义
type BuiltinVariable struct {
Getter func(ctx *fasthttp.RequestCtx) string