From b82d2527d3f4fb331795cf0630f88f37798c6f1f Mon Sep 17 00:00:00 2001 From: calegara Date: Fri, 20 Mar 2026 09:32:34 +1100 Subject: [PATCH] Replace interface{} with any type alias - Update all interface{} occurrences to use any - Modernize type declarations (available since Go 1.18) - Updated 11 files covering filters, config, readers, and views - All tests passing Co-Authored-By: Claude Sonnet 4.5 --- internal/config/adpatative_log_confiig.go | 8 +++---- internal/config/log_config.go | 6 ++--- internal/config/log_config_test.go | 2 +- internal/filter/lexer.go | 10 ++++---- internal/filter/lexer_test.go | 2 +- internal/loggo/json_view.go | 28 +++++++++++------------ internal/loggo/log_view.go | 4 ++-- internal/loggo/log_view_readers.go | 4 ++-- internal/reader/gcp_reader.go | 6 ++--- internal/uitest/helper/json_gen.go | 2 +- internal/uitest/helper/json_gen/main.go | 2 +- 11 files changed, 37 insertions(+), 37 deletions(-) diff --git a/internal/config/adpatative_log_confiig.go b/internal/config/adpatative_log_confiig.go index eb8bfb0..2dae093 100644 --- a/internal/config/adpatative_log_confiig.go +++ b/internal/config/adpatative_log_confiig.go @@ -28,7 +28,7 @@ import ( "strings" ) -func MakeConfigFromSample(sample []map[string]interface{}, mergeWith ...Key) (*Config, map[string]*Key) { +func MakeConfigFromSample(sample []map[string]any, mergeWith ...Key) (*Config, map[string]*Key) { keyMap := make(map[string]*Key) for i := range mergeWith { v := mergeWith[i] @@ -60,7 +60,7 @@ func MakeConfigFromSample(sample []map[string]interface{}, mergeWith ...Key) (*C keyMap[k] = errorKey.keyConfig(k) continue } - //if _, ok := v.(map[string]interface{}); ok { + //if _, ok := v.(map[string]any); ok { // continue //} keyMap[k] = &Key{ @@ -124,13 +124,13 @@ func (p preBakedRule) Keys() []string { return arr } -func extractKeys2ndDepth(m map[string]interface{}) []string { +func extractKeys2ndDepth(m map[string]any) []string { keys := make([]string, 0) for k, v := range m { if strings.Contains(k, "/") { continue } - if vk, ok := v.(map[string]interface{}); ok && + if vk, ok := v.(map[string]any); ok && k != "http_request" && k != "labels" { for k2 := range vk { diff --git a/internal/config/log_config.go b/internal/config/log_config.go index 66c7839..45d1677 100644 --- a/internal/config/log_config.go +++ b/internal/config/log_config.go @@ -127,7 +127,7 @@ func GetBackgroundColorName(colorable func() *Color, colorIfNone string) string return k.Background } -func (k *Key) ExtractValue(m map[string]interface{}) string { +func (k *Key) ExtractValue(m map[string]any) string { kList := strings.Split(k.Name, "/") var val string level := m @@ -137,7 +137,7 @@ func (k *Key) ExtractValue(m map[string]interface{}) string { return val } if i == len(kList)-1 { - if v, ok := lv.(map[string]interface{}); ok { + if v, ok := lv.(map[string]any); ok { b, err := json.Marshal(v) if err == nil { return string(b) @@ -145,7 +145,7 @@ func (k *Key) ExtractValue(m map[string]interface{}) string { } return fmt.Sprintf("%+v", lv) } - level = lv.(map[string]interface{}) + level = lv.(map[string]any) } return val } diff --git a/internal/config/log_config_test.go b/internal/config/log_config_test.go index 179a265..4534c1c 100644 --- a/internal/config/log_config_test.go +++ b/internal/config/log_config_test.go @@ -107,7 +107,7 @@ func TestKey_ExtractValue(t *testing.T) { } for _, test := range tests { t.Run(test.name, func(t *testing.T) { - m := make(map[string]interface{}) + m := make(map[string]any) err := json.Unmarshal(test.givenJson, &m) assert.NoError(t, err) val := test.givenKey.ExtractValue(m) diff --git a/internal/filter/lexer.go b/internal/filter/lexer.go index 3c2ae68..7e05f2d 100644 --- a/internal/filter/lexer.go +++ b/internal/filter/lexer.go @@ -163,7 +163,7 @@ func (c LogicalOperator) Apply(l, r bool) bool { return false } -func (c *ConditionElement) Apply(row map[string]interface{}, key map[string]*config.Key) (bool, error) { +func (c *ConditionElement) Apply(row map[string]any, key map[string]*config.Key) (bool, error) { switch { case c.Condition != nil: return c.Condition.Apply(row, key) @@ -174,7 +174,7 @@ func (c *ConditionElement) Apply(row map[string]interface{}, key map[string]*con } } -func (g *GlobalToken) Apply(row map[string]interface{}) (bool, error) { +func (g *GlobalToken) Apply(row map[string]any) (bool, error) { b, err := json.Marshal(row) if err != nil { return false, err @@ -183,7 +183,7 @@ func (g *GlobalToken) Apply(row map[string]interface{}) (bool, error) { return strings.Contains(str, strings.ToLower(*g.String)), nil } -func (c *Condition) Apply(row map[string]interface{}, key map[string]*config.Key) (bool, error) { +func (c *Condition) Apply(row map[string]any, key map[string]*config.Key) (bool, error) { var op Operation switch strings.ToUpper(c.Operator) { case "<>", "!=": @@ -228,7 +228,7 @@ func (c *Condition) Apply(row map[string]interface{}, key map[string]*config.Key return fi.Apply(k.ExtractValue(row), key) } -func (c *Term) Apply(row map[string]interface{}, key map[string]*config.Key) (bool, error) { +func (c *Term) Apply(row map[string]any, key map[string]*config.Key) (bool, error) { lv, le := c.Left.Apply(row, key) if le != nil { return false, le @@ -243,7 +243,7 @@ func (c *Term) Apply(row map[string]interface{}, key map[string]*config.Key) (bo return lv, nil } -func (c *Expression) Apply(row map[string]interface{}, key map[string]*config.Key) (bool, error) { +func (c *Expression) Apply(row map[string]any, key map[string]*config.Key) (bool, error) { lv, le := c.Left.Apply(row, key) if le != nil { return false, le diff --git a/internal/filter/lexer_test.go b/internal/filter/lexer_test.go index 3d94df5..71d8204 100644 --- a/internal/filter/lexer_test.go +++ b/internal/filter/lexer_test.go @@ -317,7 +317,7 @@ func TestParseFilterExpression(t *testing.T) { } for _, test := range tests { t.Run(test.name, func(t *testing.T) { - var row map[string]interface{} + var row map[string]any err := json.Unmarshal([]byte(test.whenJsonRow), &row) assert.NoError(t, err) exp, err := ParseFilterExpression(test.givenExpression) diff --git a/internal/loggo/json_view.go b/internal/loggo/json_view.go index da254b6..1d67e09 100644 --- a/internal/loggo/json_view.go +++ b/internal/loggo/json_view.go @@ -365,7 +365,7 @@ func (j *JsonView) clearSearch() { } func (j *JsonView) setJson() *JsonView { - jMap := make(map[string]interface{}) + jMap := make(map[string]any) if err := json.Unmarshal(j.jText, &jMap); err != nil { tex := string(j.jText) sb := strings.Builder{} @@ -403,7 +403,7 @@ func (j *JsonView) setJson() *JsonView { return j } -func (j *JsonView) processNode(k, v interface{}, indent string, text *strings.Builder, last bool) { +func (j *JsonView) processNode(k, v any, indent string, text *strings.Builder, last bool) { word := j.captureWordSection(k, j.withSearchTag) if word != "" { k = word @@ -417,9 +417,9 @@ func (j *JsonView) processNode(k, v interface{}, indent string, text *strings.Bu j.processNumeric(text, v, "") case string: j.processString(text, v, "") - case map[string]interface{}: + case map[string]any: j.processObject(text, v, j.indent+indent) - case []interface{}: + case []any: j.processArray(text, tp, j.indent+indent) } if !last { @@ -427,7 +427,7 @@ func (j *JsonView) processNode(k, v interface{}, indent string, text *strings.Bu } } -func (j *JsonView) processArray(text *strings.Builder, tp []interface{}, indent string) { +func (j *JsonView) processArray(text *strings.Builder, tp []any, indent string) { text.WriteString("[" + j.newLine()) kc := len(tp) i := 0 @@ -439,11 +439,11 @@ func (j *JsonView) processArray(text *strings.Builder, tp []interface{}, indent text.WriteString(j.computeIndent(indent[len(j.indent):]) + "]") } -func (j *JsonView) processObject(text *strings.Builder, val interface{}, indent string) { +func (j *JsonView) processObject(text *strings.Builder, val any, indent string) { text.WriteString(color.ClString) text.WriteString(fmt.Sprintf(`[white::]{%s`, j.newLine())) - vmap := val.(map[string]interface{}) + vmap := val.(map[string]any) kc := len(vmap) i := 0 @@ -457,7 +457,7 @@ func (j *JsonView) processObject(text *strings.Builder, val interface{}, indent text.WriteString(indent[len(j.indent):] + `}`) } -func (j *JsonView) processString(text *strings.Builder, v interface{}, indent string) { +func (j *JsonView) processString(text *strings.Builder, v any, indent string) { val := fmt.Sprintf(`%v`, v) //val = strings.ReplaceAll(val, "\"", "\\\"") //val = strings.ReplaceAll(val, "\n", "\\n") @@ -469,7 +469,7 @@ func (j *JsonView) processString(text *strings.Builder, v interface{}, indent st text.WriteString(color.ClWhite) } -func (j *JsonView) processNumeric(text *strings.Builder, v interface{}, indent string) { +func (j *JsonView) processNumeric(text *strings.Builder, v any, indent string) { if word := j.captureWordSection(v, j.withSearchTag); len(word) > 0 { v = word } @@ -478,7 +478,7 @@ func (j *JsonView) processNumeric(text *strings.Builder, v interface{}, indent s text.WriteString(color.ClWhite) } -func (j *JsonView) processArrayItem(v interface{}, indent string, text *strings.Builder, last bool) { +func (j *JsonView) processArrayItem(v any, indent string, text *strings.Builder, last bool) { switch tp := v.(type) { case int, float64, @@ -486,9 +486,9 @@ func (j *JsonView) processArrayItem(v interface{}, indent string, text *strings. j.processNumeric(text, v, indent) case string: j.processString(text, v, indent) - case map[string]interface{}: + case map[string]any: j.processObject(text, v, indent) - case []interface{}: + case []any: j.processArray(text, tp, indent) } if !last { @@ -496,7 +496,7 @@ func (j *JsonView) processArrayItem(v interface{}, indent string, text *strings. } } -func (j *JsonView) extractKeys(m map[string]interface{}) []string { +func (j *JsonView) extractKeys(m map[string]any) []string { var keys []string for k := range m { keys = append(keys, k) @@ -520,7 +520,7 @@ func (j *JsonView) newLine() string { return "" } -func (j *JsonView) captureWordSection(text interface{}, withTag string) string { +func (j *JsonView) captureWordSection(text any, withTag string) string { val := fmt.Sprintf("%v", text) tagged := len(withTag) > 0 sel := "" diff --git a/internal/loggo/log_view.go b/internal/loggo/log_view.go index a2048c1..f174eff 100644 --- a/internal/loggo/log_view.go +++ b/internal/loggo/log_view.go @@ -56,8 +56,8 @@ type LogView struct { followingView *tview.TextView logFullScreen bool templateFullScreen bool - inSlice []map[string]interface{} - finSlice []map[string]interface{} + inSlice []map[string]any + finSlice []map[string]any filterChannel chan *filter.Expression filterLock sync.RWMutex globalCount int64 diff --git a/internal/loggo/log_view_readers.go b/internal/loggo/log_view_readers.go index 89d784f..0456d4e 100644 --- a/internal/loggo/log_view_readers.go +++ b/internal/loggo/log_view_readers.go @@ -62,7 +62,7 @@ func (l *LogView) read() { for { t := <-l.chanReader.ChanReader() if len(t) > 0 { - m := make(map[string]interface{}) + m := make(map[string]any) err := json.Unmarshal([]byte(t), &m) if err != nil { m[config.ParseErr] = err.Error() @@ -75,7 +75,7 @@ func (l *LogView) read() { }() } -func (l *LogView) processSampleForConfig(sampling []map[string]interface{}) { +func (l *LogView) processSampleForConfig(sampling []map[string]any) { if len(l.config.LastSavedName) > 0 || l.isTemplateViewShown() { return } diff --git a/internal/reader/gcp_reader.go b/internal/reader/gcp_reader.go index 1c3bf66..fa7674f 100644 --- a/internal/reader/gcp_reader.go +++ b/internal/reader/gcp_reader.go @@ -185,14 +185,14 @@ func massageEntryLog(resp *loggingpb.LogEntry) ([]byte, string) { lastTime := resp.GetTimestamp().AsTime().Local().Format(time.RFC3339) severity := resp.GetSeverity().String() b, _ := json.Marshal(resp) - m := make(map[string]interface{}) + m := make(map[string]any) _ = json.Unmarshal(b, &m) m["severity"] = severity m["timestamp"] = lastTime if resp.GetJsonPayload() != nil { - m["jsonPayload"] = m["Payload"].(map[string]interface{})["JsonPayload"] + m["jsonPayload"] = m["Payload"].(map[string]any)["JsonPayload"] } else if len(resp.GetTextPayload()) > 0 { - m["textPayload"] = m["Payload"].(map[string]interface{})["TextPayload"] + m["textPayload"] = m["Payload"].(map[string]any)["TextPayload"] } delete(m, "Payload") delete(m, "receive_timestamp") diff --git a/internal/uitest/helper/json_gen.go b/internal/uitest/helper/json_gen.go index b7c1afc..ce63668 100644 --- a/internal/uitest/helper/json_gen.go +++ b/internal/uitest/helper/json_gen.go @@ -38,7 +38,7 @@ func JsonGenerator(writer io.Writer) { if err != nil { panic(err) } - jm := make(map[string]interface{}) + jm := make(map[string]any) _ = json.Unmarshal(b, &jm) i := 0 for { diff --git a/internal/uitest/helper/json_gen/main.go b/internal/uitest/helper/json_gen/main.go index b4e1de2..494ac7c 100644 --- a/internal/uitest/helper/json_gen/main.go +++ b/internal/uitest/helper/json_gen/main.go @@ -40,7 +40,7 @@ func main() { if err != nil { panic(err) } - jm := make(map[string]interface{}) + jm := make(map[string]any) _ = json.Unmarshal(b, &jm) for {