unparam 死代码清理 12→2(保留 2 处 objectstore 构造函数统一签名):移除 10 处恒 nil error / 从未使用的结果(getPoWConfigForRoute 的恒 nil *PoWConfig、getSQLiteOverview/getPostgresOverview/getStatus/loadKumaConfig/filterExpectedRoutes 的恒 nil error、rawJSONString/parsePositiveInt 的弃用 bool、buildProxyRoute 的弃用 []ZoneDomain、getLocked 的恒 nil error),同步简化 12+ 处调用方与死错误检查。9 个受影响包测试通过。metric 持平 8(改进在基准之外)。

Result: {"status":"keep","total_issues":8,"golint_canonicalheader":0,"golint_errname":0,"golint_errorlint":1,"golint_exhaustive":0,"golint_forcetypeassert":0,"golint_gosec":0,"golint_intrange":0,"golint_modernize":3,"golint_nilnil":3,"golint_perfsprint":0,"golint_prealloc":0,"golint_recvcheck":1,"golint_usestdlibvars":0,"golint_wastedassign":0,"golint_total":8,"golint_test_testifylint":0,"golint_test_thelper":0,"golint_test_usetesting":0,"golint_test_total":0,"golint_vetx_total":0,"eslint_problems":0,"eslint_errors":0,"eslint_warnings":0,"tsc_errors":0,"measure_s":43}
This commit is contained in:
ryan
2026-08-16 18:29:51 +08:00
parent d7b8f44f90
commit c85373ff47
12 changed files with 64 additions and 80 deletions
+10 -9
View File
@@ -52,20 +52,21 @@ func NewMemoryStore(cleanupInterval time.Duration) *MemoryStore {
func (s *MemoryStore) Get(_ context.Context, key string) (string, bool, error) {
s.mu.Lock()
defer s.mu.Unlock()
return s.getLocked(key)
val, ok := s.getLocked(key)
return val, ok, nil
}
// getLocked is the internal helper – caller must hold s.mu.
func (s *MemoryStore) getLocked(key string) (string, bool, error) {
func (s *MemoryStore) getLocked(key string) (string, bool) {
item, found := s.items[key]
if !found {
return "", false, nil
return "", false
}
if time.Now().After(item.expiresAt) {
delete(s.items, key)
return "", false, nil
return "", false
}
return item.value, true, nil
return item.value, true
}
// Set 向 MemoryStore 写入指定 key 的值
@@ -93,7 +94,7 @@ func (s *MemoryStore) SetNX(_ context.Context, key string, val string, ttl time.
s.mu.Lock()
defer s.mu.Unlock()
_, exists, _ := s.getLocked(key)
_, exists := s.getLocked(key)
if exists {
return false, nil
}
@@ -109,9 +110,9 @@ func (s *MemoryStore) GetAndDelete(_ context.Context, key string) (string, bool,
s.mu.Lock()
defer s.mu.Unlock()
val, exists, err := s.getLocked(key)
if err != nil || !exists {
return "", false, err
val, exists := s.getLocked(key)
if !exists {
return "", false, nil
}
delete(s.items, key)
return val, true, nil
+4 -4
View File
@@ -104,7 +104,7 @@ func RenderRouteConfig(doc Document, certificateFiles []SupportFile) (string, er
displayName := resolveRouteSiteName(route)
cacheConfig := routeCacheConfig{Enabled: route.CacheEnabled, Policy: route.CachePolicy, Rules: route.CacheRules}
limitConfig := mergeRouteLimitConfig(route, doc.OpenRestyConfig)
powEnabled, _ := getPoWConfigForRoute(route.ID, doc.WAF)
powEnabled := getPoWConfigForRoute(route.ID, doc.WAF)
if normalizeRouteUpstreamType(route.UpstreamType) == routeUpstreamTypePages {
if err := renderPagesRoute(&builder, route, displayName, serverNames, certificates, limitConfig, powEnabled, doc.OpenRestyConfig); err != nil {
return "", err
@@ -827,7 +827,7 @@ func validateCertificateCoverage(certPEM string, domains []string) error {
return nil
}
func getPoWConfigForRoute(routeID uint, snapshot WAFDocument) (bool, *PoWConfig) {
func getPoWConfigForRoute(routeID uint, snapshot WAFDocument) bool {
enabledGroups := make(map[uint]WAFRuleGroup, len(snapshot.RuleGroups))
globalGroupIDs := make([]uint, 0)
for _, group := range snapshot.RuleGroups {
@@ -857,10 +857,10 @@ func getPoWConfigForRoute(routeID uint, snapshot WAFDocument) (bool, *PoWConfig)
for _, groupID := range activeGroupIDs {
group := enabledGroups[groupID]
if graphContainsNodeType(group.Graph, "pow") {
return true, nil
return true
}
}
return false, nil
return false
}
func graphContainsNodeType(graph WAFRuleGraph, nodeType string) bool {
+1 -4
View File
@@ -108,13 +108,10 @@ func TestGetPoWConfigForRouteUsesGlobalGroupWithoutExplicitBinding(t *testing.T)
},
}
enabled, config := getPoWConfigForRoute(42, snapshot)
enabled := getPoWConfigForRoute(42, snapshot)
if !enabled {
t.Fatal("expected pow to be enabled via global rule group")
}
if config != nil {
t.Fatalf("expected node config to stay in runtime graph, got legacy config %#v", config)
}
}
func TestRenderRouteConfigEnablesPoWLocationsFromRuntimeGraph(t *testing.T) {