From 599bdb74efcc97e86ce6023c1ae8265b1c2ff33b Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Thu, 29 Jan 2026 21:39:06 +0200 Subject: refactor: improve Go best practices compliance - Add explicit interface satisfaction checks (var _ Interface = (*Type)(nil)) for compile-time verification: - TurboWriter implementations (DirectTurboWriter, TurboChannelWriter) - Processor implementations (GrepLineProcessor, ChannellessLineProcessor) - Parser implementations (genericParser, csvParser, genericKVParser, custom parsers, mimecastParser) - Logger implementations (file, stdout) - Handler implementations (ServerHandler, ClientHandler) - Connector implementations (Serverless, ServerConnection) - SSH callback implementations (KnownHostsCallback) - Improve error handling with context wrapping (%w): - SSH operations: GeneratePrivateRSAKey, Agent - Query parsing: Query.parse - SSH client connections: dial, session, handle methods - Fix receiver consistency: - Convert Query.String() from value to pointer receiver - Convert Outfile.String() from value to pointer receiver - Convert all KnownHostsCallback methods to pointer receivers - Convert mapCommand.Start() to pointer receiver - Reorganize file structure for better clarity: - internal/io/dlog/dlog.go: Move type definition before public functions - internal/mapr/token.go: Reorganize helper functions after public ones - Add documentation comments: - Query.String() method - Outfile.String() method - Regex.String() method - Improve config variable documentation All unit tests and integration tests pass. Amp-Thread-ID: https://ampcode.com/threads/T-019c0b08-0eeb-705d-a1f7-31bb764b659a Co-authored-by: Amp --- internal/server/handlers/channelless_adapter.go | 2 ++ internal/server/handlers/lineprocessor.go | 3 +++ internal/server/handlers/mapcommand.go | 2 +- internal/server/handlers/serverhandler.go | 2 ++ internal/server/handlers/turbo_writer.go | 4 ++++ 5 files changed, 12 insertions(+), 1 deletion(-) (limited to 'internal/server') diff --git a/internal/server/handlers/channelless_adapter.go b/internal/server/handlers/channelless_adapter.go index a950408..40c072f 100644 --- a/internal/server/handlers/channelless_adapter.go +++ b/internal/server/handlers/channelless_adapter.go @@ -13,6 +13,8 @@ type ChannellessLineProcessor struct { lineCount uint64 } +var _ line.Processor = (*ChannellessLineProcessor)(nil) + // NewChannellessLineProcessor creates a processor that sends lines to the existing channel func NewChannellessLineProcessor(lines chan<- *line.Line, globID string) *ChannellessLineProcessor { return &ChannellessLineProcessor{ diff --git a/internal/server/handlers/lineprocessor.go b/internal/server/handlers/lineprocessor.go index f75b85b..9bbf7e1 100644 --- a/internal/server/handlers/lineprocessor.go +++ b/internal/server/handlers/lineprocessor.go @@ -6,6 +6,7 @@ import ( "io" "sync" + "github.com/mimecast/dtail/internal/io/line" "github.com/mimecast/dtail/internal/io/pool" "github.com/mimecast/dtail/internal/protocol" ) @@ -28,6 +29,8 @@ type GrepLineProcessor struct { bytesWritten uint64 } +var _ line.Processor = (*GrepLineProcessor)(nil) + // HandlerWriter adapts a ServerHandler to implement io.Writer type HandlerWriter struct { handler *ServerHandler diff --git a/internal/server/handlers/mapcommand.go b/internal/server/handlers/mapcommand.go index 83c4c75..a4fda97 100644 --- a/internal/server/handlers/mapcommand.go +++ b/internal/server/handlers/mapcommand.go @@ -45,7 +45,7 @@ func newMapCommand(serverHandler *ServerHandler, argc int, return m, aggregate, nil, nil } -func (m mapCommand) Start(ctx context.Context, aggregatedMessages chan<- string) { +func (m *mapCommand) Start(ctx context.Context, aggregatedMessages chan<- string) { if m.turboAggregate != nil { m.turboAggregate.Start(ctx, aggregatedMessages) } else { diff --git a/internal/server/handlers/serverhandler.go b/internal/server/handlers/serverhandler.go index df227ab..645e2e9 100644 --- a/internal/server/handlers/serverhandler.go +++ b/internal/server/handlers/serverhandler.go @@ -26,6 +26,8 @@ type ServerHandler struct { pendingFiles int32 } +var _ Handler = (*ServerHandler)(nil) + // NewServerHandler returns the server handler. func NewServerHandler(user *user.User, catLimiter, tailLimiter chan struct{}) *ServerHandler { diff --git a/internal/server/handlers/turbo_writer.go b/internal/server/handlers/turbo_writer.go index d8ee2ad..62225bd 100644 --- a/internal/server/handlers/turbo_writer.go +++ b/internal/server/handlers/turbo_writer.go @@ -40,6 +40,8 @@ type DirectTurboWriter struct { bytesWritten uint64 } +var _ TurboWriter = (*DirectTurboWriter)(nil) + // NewDirectTurboWriter creates a new turbo writer func NewDirectTurboWriter(writer io.Writer, hostname string, plain, serverless bool) *DirectTurboWriter { return &DirectTurboWriter{ @@ -252,6 +254,8 @@ type TurboChannelWriter struct { bytesWritten uint64 } +var _ TurboWriter = (*TurboChannelWriter)(nil) + // NewTurboChannelWriter creates a writer that sends to a turbo channel func NewTurboChannelWriter(channel chan<- []byte, hostname string, plain, serverless bool) *TurboChannelWriter { return &TurboChannelWriter{ -- cgit v1.2.3