feat: introduce theme management and performance improvements (#7)

This commit is contained in:
Karol Broda
2025-12-24 10:49:03 +01:00
committed by Karol Broda
parent 9b09ee7c6c
commit 933da8bad2
20 changed files with 877 additions and 172 deletions

View File

@@ -2,12 +2,16 @@ package resolver
import (
"context"
"fmt"
"net"
"os"
"strconv"
"sync"
"time"
)
var debugTiming = os.Getenv("SNITCH_DEBUG_TIMING") != ""
// Resolver handles DNS and service name resolution with caching and timeouts
type Resolver struct {
timeout time.Duration
@@ -41,6 +45,7 @@ func (r *Resolver) ResolveAddr(addr string) string {
}
// Perform resolution with timeout
start := time.Now()
ctx, cancel := context.WithTimeout(context.Background(), r.timeout)
defer cancel()
@@ -55,6 +60,11 @@ func (r *Resolver) ResolveAddr(addr string) string {
}
}
elapsed := time.Since(start)
if debugTiming && elapsed > 50*time.Millisecond {
fmt.Fprintf(os.Stderr, "[timing] slow DNS lookup: %s -> %s (%v)\n", addr, resolved, elapsed)
}
// Cache the result
r.mutex.Lock()
r.cache[addr] = resolved