Skip to content

Commit b82d252

Browse files
aurcclaude
andcommitted
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 <noreply@anthropic.com>
1 parent adc90d7 commit b82d252

11 files changed

Lines changed: 37 additions & 37 deletions

File tree

internal/config/adpatative_log_confiig.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"strings"
2929
)
3030

31-
func MakeConfigFromSample(sample []map[string]interface{}, mergeWith ...Key) (*Config, map[string]*Key) {
31+
func MakeConfigFromSample(sample []map[string]any, mergeWith ...Key) (*Config, map[string]*Key) {
3232
keyMap := make(map[string]*Key)
3333
for i := range mergeWith {
3434
v := mergeWith[i]
@@ -60,7 +60,7 @@ func MakeConfigFromSample(sample []map[string]interface{}, mergeWith ...Key) (*C
6060
keyMap[k] = errorKey.keyConfig(k)
6161
continue
6262
}
63-
//if _, ok := v.(map[string]interface{}); ok {
63+
//if _, ok := v.(map[string]any); ok {
6464
// continue
6565
//}
6666
keyMap[k] = &Key{
@@ -124,13 +124,13 @@ func (p preBakedRule) Keys() []string {
124124
return arr
125125
}
126126

127-
func extractKeys2ndDepth(m map[string]interface{}) []string {
127+
func extractKeys2ndDepth(m map[string]any) []string {
128128
keys := make([]string, 0)
129129
for k, v := range m {
130130
if strings.Contains(k, "/") {
131131
continue
132132
}
133-
if vk, ok := v.(map[string]interface{}); ok &&
133+
if vk, ok := v.(map[string]any); ok &&
134134
k != "http_request" &&
135135
k != "labels" {
136136
for k2 := range vk {

internal/config/log_config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func GetBackgroundColorName(colorable func() *Color, colorIfNone string) string
127127
return k.Background
128128
}
129129

130-
func (k *Key) ExtractValue(m map[string]interface{}) string {
130+
func (k *Key) ExtractValue(m map[string]any) string {
131131
kList := strings.Split(k.Name, "/")
132132
var val string
133133
level := m
@@ -137,15 +137,15 @@ func (k *Key) ExtractValue(m map[string]interface{}) string {
137137
return val
138138
}
139139
if i == len(kList)-1 {
140-
if v, ok := lv.(map[string]interface{}); ok {
140+
if v, ok := lv.(map[string]any); ok {
141141
b, err := json.Marshal(v)
142142
if err == nil {
143143
return string(b)
144144
}
145145
}
146146
return fmt.Sprintf("%+v", lv)
147147
}
148-
level = lv.(map[string]interface{})
148+
level = lv.(map[string]any)
149149
}
150150
return val
151151
}

internal/config/log_config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func TestKey_ExtractValue(t *testing.T) {
107107
}
108108
for _, test := range tests {
109109
t.Run(test.name, func(t *testing.T) {
110-
m := make(map[string]interface{})
110+
m := make(map[string]any)
111111
err := json.Unmarshal(test.givenJson, &m)
112112
assert.NoError(t, err)
113113
val := test.givenKey.ExtractValue(m)

internal/filter/lexer.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func (c LogicalOperator) Apply(l, r bool) bool {
163163
return false
164164
}
165165

166-
func (c *ConditionElement) Apply(row map[string]interface{}, key map[string]*config.Key) (bool, error) {
166+
func (c *ConditionElement) Apply(row map[string]any, key map[string]*config.Key) (bool, error) {
167167
switch {
168168
case c.Condition != nil:
169169
return c.Condition.Apply(row, key)
@@ -174,7 +174,7 @@ func (c *ConditionElement) Apply(row map[string]interface{}, key map[string]*con
174174
}
175175
}
176176

177-
func (g *GlobalToken) Apply(row map[string]interface{}) (bool, error) {
177+
func (g *GlobalToken) Apply(row map[string]any) (bool, error) {
178178
b, err := json.Marshal(row)
179179
if err != nil {
180180
return false, err
@@ -183,7 +183,7 @@ func (g *GlobalToken) Apply(row map[string]interface{}) (bool, error) {
183183
return strings.Contains(str, strings.ToLower(*g.String)), nil
184184
}
185185

186-
func (c *Condition) Apply(row map[string]interface{}, key map[string]*config.Key) (bool, error) {
186+
func (c *Condition) Apply(row map[string]any, key map[string]*config.Key) (bool, error) {
187187
var op Operation
188188
switch strings.ToUpper(c.Operator) {
189189
case "<>", "!=":
@@ -228,7 +228,7 @@ func (c *Condition) Apply(row map[string]interface{}, key map[string]*config.Key
228228
return fi.Apply(k.ExtractValue(row), key)
229229
}
230230

231-
func (c *Term) Apply(row map[string]interface{}, key map[string]*config.Key) (bool, error) {
231+
func (c *Term) Apply(row map[string]any, key map[string]*config.Key) (bool, error) {
232232
lv, le := c.Left.Apply(row, key)
233233
if le != nil {
234234
return false, le
@@ -243,7 +243,7 @@ func (c *Term) Apply(row map[string]interface{}, key map[string]*config.Key) (bo
243243
return lv, nil
244244
}
245245

246-
func (c *Expression) Apply(row map[string]interface{}, key map[string]*config.Key) (bool, error) {
246+
func (c *Expression) Apply(row map[string]any, key map[string]*config.Key) (bool, error) {
247247
lv, le := c.Left.Apply(row, key)
248248
if le != nil {
249249
return false, le

internal/filter/lexer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ func TestParseFilterExpression(t *testing.T) {
317317
}
318318
for _, test := range tests {
319319
t.Run(test.name, func(t *testing.T) {
320-
var row map[string]interface{}
320+
var row map[string]any
321321
err := json.Unmarshal([]byte(test.whenJsonRow), &row)
322322
assert.NoError(t, err)
323323
exp, err := ParseFilterExpression(test.givenExpression)

internal/loggo/json_view.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ func (j *JsonView) clearSearch() {
365365
}
366366

367367
func (j *JsonView) setJson() *JsonView {
368-
jMap := make(map[string]interface{})
368+
jMap := make(map[string]any)
369369
if err := json.Unmarshal(j.jText, &jMap); err != nil {
370370
tex := string(j.jText)
371371
sb := strings.Builder{}
@@ -403,7 +403,7 @@ func (j *JsonView) setJson() *JsonView {
403403
return j
404404
}
405405

406-
func (j *JsonView) processNode(k, v interface{}, indent string, text *strings.Builder, last bool) {
406+
func (j *JsonView) processNode(k, v any, indent string, text *strings.Builder, last bool) {
407407
word := j.captureWordSection(k, j.withSearchTag)
408408
if word != "" {
409409
k = word
@@ -417,17 +417,17 @@ func (j *JsonView) processNode(k, v interface{}, indent string, text *strings.Bu
417417
j.processNumeric(text, v, "")
418418
case string:
419419
j.processString(text, v, "")
420-
case map[string]interface{}:
420+
case map[string]any:
421421
j.processObject(text, v, j.indent+indent)
422-
case []interface{}:
422+
case []any:
423423
j.processArray(text, tp, j.indent+indent)
424424
}
425425
if !last {
426426
text.WriteString(",")
427427
}
428428
}
429429

430-
func (j *JsonView) processArray(text *strings.Builder, tp []interface{}, indent string) {
430+
func (j *JsonView) processArray(text *strings.Builder, tp []any, indent string) {
431431
text.WriteString("[" + j.newLine())
432432
kc := len(tp)
433433
i := 0
@@ -439,11 +439,11 @@ func (j *JsonView) processArray(text *strings.Builder, tp []interface{}, indent
439439
text.WriteString(j.computeIndent(indent[len(j.indent):]) + "]")
440440
}
441441

442-
func (j *JsonView) processObject(text *strings.Builder, val interface{}, indent string) {
442+
func (j *JsonView) processObject(text *strings.Builder, val any, indent string) {
443443
text.WriteString(color.ClString)
444444
text.WriteString(fmt.Sprintf(`[white::]{%s`, j.newLine()))
445445

446-
vmap := val.(map[string]interface{})
446+
vmap := val.(map[string]any)
447447
kc := len(vmap)
448448
i := 0
449449

@@ -457,7 +457,7 @@ func (j *JsonView) processObject(text *strings.Builder, val interface{}, indent
457457
text.WriteString(indent[len(j.indent):] + `}`)
458458
}
459459

460-
func (j *JsonView) processString(text *strings.Builder, v interface{}, indent string) {
460+
func (j *JsonView) processString(text *strings.Builder, v any, indent string) {
461461
val := fmt.Sprintf(`%v`, v)
462462
//val = strings.ReplaceAll(val, "\"", "\\\"")
463463
//val = strings.ReplaceAll(val, "\n", "\\n")
@@ -469,7 +469,7 @@ func (j *JsonView) processString(text *strings.Builder, v interface{}, indent st
469469
text.WriteString(color.ClWhite)
470470
}
471471

472-
func (j *JsonView) processNumeric(text *strings.Builder, v interface{}, indent string) {
472+
func (j *JsonView) processNumeric(text *strings.Builder, v any, indent string) {
473473
if word := j.captureWordSection(v, j.withSearchTag); len(word) > 0 {
474474
v = word
475475
}
@@ -478,25 +478,25 @@ func (j *JsonView) processNumeric(text *strings.Builder, v interface{}, indent s
478478
text.WriteString(color.ClWhite)
479479
}
480480

481-
func (j *JsonView) processArrayItem(v interface{}, indent string, text *strings.Builder, last bool) {
481+
func (j *JsonView) processArrayItem(v any, indent string, text *strings.Builder, last bool) {
482482
switch tp := v.(type) {
483483
case int,
484484
float64,
485485
bool:
486486
j.processNumeric(text, v, indent)
487487
case string:
488488
j.processString(text, v, indent)
489-
case map[string]interface{}:
489+
case map[string]any:
490490
j.processObject(text, v, indent)
491-
case []interface{}:
491+
case []any:
492492
j.processArray(text, tp, indent)
493493
}
494494
if !last {
495495
text.WriteString(",")
496496
}
497497
}
498498

499-
func (j *JsonView) extractKeys(m map[string]interface{}) []string {
499+
func (j *JsonView) extractKeys(m map[string]any) []string {
500500
var keys []string
501501
for k := range m {
502502
keys = append(keys, k)
@@ -520,7 +520,7 @@ func (j *JsonView) newLine() string {
520520
return ""
521521
}
522522

523-
func (j *JsonView) captureWordSection(text interface{}, withTag string) string {
523+
func (j *JsonView) captureWordSection(text any, withTag string) string {
524524
val := fmt.Sprintf("%v", text)
525525
tagged := len(withTag) > 0
526526
sel := ""

internal/loggo/log_view.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ type LogView struct {
5656
followingView *tview.TextView
5757
logFullScreen bool
5858
templateFullScreen bool
59-
inSlice []map[string]interface{}
60-
finSlice []map[string]interface{}
59+
inSlice []map[string]any
60+
finSlice []map[string]any
6161
filterChannel chan *filter.Expression
6262
filterLock sync.RWMutex
6363
globalCount int64

internal/loggo/log_view_readers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (l *LogView) read() {
6262
for {
6363
t := <-l.chanReader.ChanReader()
6464
if len(t) > 0 {
65-
m := make(map[string]interface{})
65+
m := make(map[string]any)
6666
err := json.Unmarshal([]byte(t), &m)
6767
if err != nil {
6868
m[config.ParseErr] = err.Error()
@@ -75,7 +75,7 @@ func (l *LogView) read() {
7575
}()
7676
}
7777

78-
func (l *LogView) processSampleForConfig(sampling []map[string]interface{}) {
78+
func (l *LogView) processSampleForConfig(sampling []map[string]any) {
7979
if len(l.config.LastSavedName) > 0 || l.isTemplateViewShown() {
8080
return
8181
}

internal/reader/gcp_reader.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,14 @@ func massageEntryLog(resp *loggingpb.LogEntry) ([]byte, string) {
185185
lastTime := resp.GetTimestamp().AsTime().Local().Format(time.RFC3339)
186186
severity := resp.GetSeverity().String()
187187
b, _ := json.Marshal(resp)
188-
m := make(map[string]interface{})
188+
m := make(map[string]any)
189189
_ = json.Unmarshal(b, &m)
190190
m["severity"] = severity
191191
m["timestamp"] = lastTime
192192
if resp.GetJsonPayload() != nil {
193-
m["jsonPayload"] = m["Payload"].(map[string]interface{})["JsonPayload"]
193+
m["jsonPayload"] = m["Payload"].(map[string]any)["JsonPayload"]
194194
} else if len(resp.GetTextPayload()) > 0 {
195-
m["textPayload"] = m["Payload"].(map[string]interface{})["TextPayload"]
195+
m["textPayload"] = m["Payload"].(map[string]any)["TextPayload"]
196196
}
197197
delete(m, "Payload")
198198
delete(m, "receive_timestamp")

internal/uitest/helper/json_gen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func JsonGenerator(writer io.Writer) {
3838
if err != nil {
3939
panic(err)
4040
}
41-
jm := make(map[string]interface{})
41+
jm := make(map[string]any)
4242
_ = json.Unmarshal(b, &jm)
4343
i := 0
4444
for {

0 commit comments

Comments
 (0)