fix: dns resolution taking long and add caching options (#8)

This commit is contained in:
Karol Broda
2025-12-24 11:12:39 +01:00
committed by Karol Broda
parent 933da8bad2
commit 49948de0ed
13 changed files with 1302 additions and 67 deletions

View File

@@ -6,16 +6,15 @@ import (
tea "github.com/charmbracelet/bubbletea"
"github.com/karol-broda/snitch/internal/config"
"github.com/karol-broda/snitch/internal/resolver"
"github.com/karol-broda/snitch/internal/tui"
"github.com/spf13/cobra"
)
// top-specific flags
var (
topTheme string
topInterval time.Duration
topResolveAddrs bool
topResolvePorts bool
topTheme string
topInterval time.Duration
)
var topCmd = &cobra.Command{
@@ -29,11 +28,16 @@ var topCmd = &cobra.Command{
theme = cfg.Defaults.Theme
}
// configure resolver with cache setting
effectiveNoCache := noCache || !cfg.Defaults.DNSCache
resolver.SetNoCache(effectiveNoCache)
opts := tui.Options{
Theme: theme,
Interval: topInterval,
ResolveAddrs: topResolveAddrs,
ResolvePorts: topResolvePorts,
ResolveAddrs: resolveAddrs,
ResolvePorts: resolvePorts,
NoCache: effectiveNoCache,
}
// if any filter flag is set, use exclusive mode
@@ -62,9 +66,8 @@ func init() {
// top-specific flags
topCmd.Flags().StringVar(&topTheme, "theme", cfg.Defaults.Theme, "Theme for TUI (see 'snitch themes')")
topCmd.Flags().DurationVarP(&topInterval, "interval", "i", time.Second, "Refresh interval")
topCmd.Flags().BoolVar(&topResolveAddrs, "resolve-addrs", !cfg.Defaults.Numeric, "Resolve IP addresses to hostnames")
topCmd.Flags().BoolVar(&topResolvePorts, "resolve-ports", false, "Resolve port numbers to service names")
// shared filter flags
// shared flags
addFilterFlags(topCmd)
addResolutionFlags(topCmd)
}