summaryrefslogtreecommitdiff
path: root/internal/mapr
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-01-29 21:39:06 +0200
committerPaul Buetow <paul@buetow.org>2026-01-29 21:39:06 +0200
commit599bdb74efcc97e86ce6023c1ae8265b1c2ff33b (patch)
tree6642a7401de622efc90947586f4db7a3e6ccd75d /internal/mapr
parenta32f028487c2e0b9e3144cf82d4153d1cd4a5243 (diff)
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 <amp@ampcode.com>
Diffstat (limited to 'internal/mapr')
-rw-r--r--internal/mapr/logformat/csv.go2
-rw-r--r--internal/mapr/logformat/custom1.go2
-rw-r--r--internal/mapr/logformat/custom2.go2
-rw-r--r--internal/mapr/logformat/generic.go2
-rw-r--r--internal/mapr/logformat/generickv.go2
-rw-r--r--internal/mapr/logformat/mimecast.go2
-rw-r--r--internal/mapr/query.go8
-rw-r--r--internal/mapr/token.go33
8 files changed, 34 insertions, 19 deletions
diff --git a/internal/mapr/logformat/csv.go b/internal/mapr/logformat/csv.go
index ea85ca9..b8f565c 100644
--- a/internal/mapr/logformat/csv.go
+++ b/internal/mapr/logformat/csv.go
@@ -13,6 +13,8 @@ type csvParser struct {
hasHeader bool
}
+var _ Parser = (*csvParser)(nil)
+
func newCSVParser(hostname, timeZoneName string, timeZoneOffset int) (*csvParser, error) {
defaultParser, err := newDefaultParser(hostname, timeZoneName, timeZoneOffset)
if err != nil {
diff --git a/internal/mapr/logformat/custom1.go b/internal/mapr/logformat/custom1.go
index 7229f3e..05e0867 100644
--- a/internal/mapr/logformat/custom1.go
+++ b/internal/mapr/logformat/custom1.go
@@ -7,6 +7,8 @@ var ErrCustom1NotImplemented error = errors.New("custom1 log format is not imple
// Template for creating a custom log format.
type custom1Parser struct{}
+var _ Parser = (*custom1Parser)(nil)
+
func newCustom1Parser(hostname, timeZoneName string, timeZoneOffset int) (*custom1Parser, error) {
return &custom1Parser{}, ErrCustom1NotImplemented
}
diff --git a/internal/mapr/logformat/custom2.go b/internal/mapr/logformat/custom2.go
index 262c721..cc8d5b9 100644
--- a/internal/mapr/logformat/custom2.go
+++ b/internal/mapr/logformat/custom2.go
@@ -7,6 +7,8 @@ var ErrCustom2NotImplemented error = errors.New("custom2 log format is not imple
// Template for creating a custom log format.
type custom2Parser struct{}
+var _ Parser = (*custom2Parser)(nil)
+
func newCustom2Parser(hostname, timeZoneName string, timeZoneOffset int) (*custom2Parser, error) {
return &custom2Parser{}, ErrCustom2NotImplemented
}
diff --git a/internal/mapr/logformat/generic.go b/internal/mapr/logformat/generic.go
index 32d9b4a..1350eff 100644
--- a/internal/mapr/logformat/generic.go
+++ b/internal/mapr/logformat/generic.go
@@ -4,6 +4,8 @@ type genericParser struct {
defaultParser
}
+var _ Parser = (*genericParser)(nil)
+
func newGenericParser(hostname, timeZoneName string, timeZoneOffset int) (*genericParser, error) {
defaultParser, err := newDefaultParser(hostname, timeZoneName, timeZoneOffset)
if err != nil {
diff --git a/internal/mapr/logformat/generickv.go b/internal/mapr/logformat/generickv.go
index 9c3de92..bd9aad5 100644
--- a/internal/mapr/logformat/generickv.go
+++ b/internal/mapr/logformat/generickv.go
@@ -10,6 +10,8 @@ type genericKVParser struct {
defaultParser
}
+var _ Parser = (*genericKVParser)(nil)
+
func newGenericKVParser(hostname, timeZoneName string, timeZoneOffset int) (*genericKVParser, error) {
defaultParser, err := newDefaultParser(hostname, timeZoneName, timeZoneOffset)
if err != nil {
diff --git a/internal/mapr/logformat/mimecast.go b/internal/mapr/logformat/mimecast.go
index cf6b333..84e1e93 100644
--- a/internal/mapr/logformat/mimecast.go
+++ b/internal/mapr/logformat/mimecast.go
@@ -10,6 +10,8 @@ var ErrMimecastNotAvailable error = errors.New("The mimecast logformat is not av
type mimecastParser struct{}
+var _ Parser = (*mimecastParser)(nil)
+
func newMimecastParser(hostname, timeZoneName string, timeZoneOffset int) (*mimecastParser, error) {
return &mimecastParser{}, ErrMimecastNotAvailable
}
diff --git a/internal/mapr/query.go b/internal/mapr/query.go
index 139f04c..06a8dc2 100644
--- a/internal/mapr/query.go
+++ b/internal/mapr/query.go
@@ -19,7 +19,8 @@ type Outfile struct {
AppendMode bool
}
-func (o Outfile) String() string {
+// String returns the string representation of Outfile.
+func (o *Outfile) String() string {
return fmt.Sprintf("Outfile(FilePath:%v,AppendMode:%v)", o.FilePath, o.AppendMode)
}
@@ -41,7 +42,8 @@ type Query struct {
LogFormat string
}
-func (q Query) String() string {
+// String returns the string representation of Query.
+func (q *Query) String() string {
return fmt.Sprintf("Query(Select:%v,Table:%s,Where:%v,Set:%vGroupBy:%v,"+
"GroupKey:%s,OrderBy:%v,ReverseOrder:%v,Interval:%v,Limit:%d,Outfile:%s,"+
"RawQuery:%s,tokens:%v,LogFormat:%s)",
@@ -95,7 +97,7 @@ func (q *Query) Has(what string) bool {
func (q *Query) parse(tokens []token) error {
if _, err := q.parseTokens(tokens); err != nil {
- return err
+ return fmt.Errorf("failed to parse query tokens: %w", err)
}
if len(q.Select) < 1 {
diff --git a/internal/mapr/token.go b/internal/mapr/token.go
index 77362f7..b9b02f8 100644
--- a/internal/mapr/token.go
+++ b/internal/mapr/token.go
@@ -14,22 +14,7 @@ type token struct {
quotesStripped bool
}
-func (t token) isKeyword() bool {
- if !t.isBareword {
- return false
- }
- for _, keyword := range keywords {
- if strings.ToLower(t.str) == keyword {
- return true
- }
- }
- return false
-}
-
-func (t token) String() string {
- return t.str
-}
-
+// tokenize parses a query string into tokens.
func tokenize(queryStr string) []token {
var tokens []token
for i, part := range strings.Split(queryStr, "\"") {
@@ -105,3 +90,19 @@ func tokensConsumeOptional(tokens []token, optional string) []token {
}
return tokens
}
+
+func (t token) isKeyword() bool {
+ if !t.isBareword {
+ return false
+ }
+ for _, keyword := range keywords {
+ if strings.ToLower(t.str) == keyword {
+ return true
+ }
+ }
+ return false
+}
+
+func (t token) String() string {
+ return t.str
+}