diff options
| author | Paul Buetow <paul@buetow.org> | 2025-06-19 17:00:58 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-06-19 17:00:58 +0300 |
| commit | 655e348870712280eac03d9e32d027e74c119ced (patch) | |
| tree | fe9546bf96e0d8d7a30d87d7d4936dc4bea31ca8 /internal/ssh/client | |
| parent | 0234fbac3490ccf2b9dca36292ad6459e990e0f5 (diff) | |
Refactor: Extract magic numbers as constants and reduce client code duplication
- Created internal/constants package with organized constant files:
- timeouts.go: All time duration constants (timeouts, intervals, delays)
- channels.go: Channel buffer size constants
- limits.go: Numeric limits and configuration values
- buffers.go: Buffer size constants in bytes
- Replaced all magic numbers throughout codebase with named constants:
- Time durations (2s, 3s, 5s, 10s, 100ms, 24h) now use descriptive constants
- Buffer sizes (8KB, 64KB, 1MB) extracted to constants
- Channel buffer sizes and multipliers
- Configuration limits (max connections, concurrency, etc.)
- Health check status codes
- Percentage calculations
- Reduced code duplication in client implementations:
- Created CommonClient to share functionality between CatClient, GrepClient, and TailClient
- All three clients now inherit from CommonClient
- Eliminated duplicate makeHandler() and makeCommands() methods
- Simplified client constructors
This refactoring improves code maintainability by centralizing configuration values
and reducing redundant code across similar client implementations.
Diffstat (limited to 'internal/ssh/client')
| -rw-r--r-- | internal/ssh/client/knownhostscallback.go | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/internal/ssh/client/knownhostscallback.go b/internal/ssh/client/knownhostscallback.go index 393c4c7..d5f605f 100644 --- a/internal/ssh/client/knownhostscallback.go +++ b/internal/ssh/client/knownhostscallback.go @@ -10,6 +10,7 @@ import ( "sync" "time" + "github.com/mimecast/dtail/internal/constants" "github.com/mimecast/dtail/internal/io/dlog" "github.com/mimecast/dtail/internal/io/prompt" @@ -125,7 +126,7 @@ func (c KnownHostsCallback) PromptAddHosts(ctx context.Context) { c.promptAddHosts(hosts) hosts = []unknownHost{} } - case <-time.After(2 * time.Second): + case <-time.After(constants.KnownHostsCallbackTimeout): // Or ask when after 2 seconds no new unknown hosts were added. if len(hosts) > 0 { c.promptAddHosts(hosts) |
