Skip to content

Commit b85577f

Browse files
committed
Fix go-critic errors
1 parent bb8c63c commit b85577f

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

golang/pkg/flatted/flatted.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
type flattedIndex string
1414

1515
// Stringify converts a Go value into a specialized flatted JSON string.
16-
func Stringify(value any, replacer any, space any) (string, error) {
16+
func Stringify(value, replacer, space any) (string, error) {
1717
knownKeys := []any{}
1818
knownValues := []string{}
1919
input := []any{}
@@ -123,10 +123,11 @@ func Stringify(value any, replacer any, space any) (string, error) {
123123
var b []byte
124124
var err error
125125
indent := ""
126-
if s, ok := space.(string); ok {
127-
indent = s
128-
} else if i, ok := space.(int); ok {
129-
indent = strings.Repeat(" ", i)
126+
switch v := space.(type) {
127+
case string:
128+
indent = v
129+
case int:
130+
indent = strings.Repeat(" ", v)
130131
}
131132

132133
if indent != "" {
@@ -205,18 +206,19 @@ func Parse(text string, reviver func(key string, value any) any) (any, error) {
205206
}
206207

207208
func revive(key string, value any, reviver func(k string, v any) any) any {
208-
if arr, ok := value.([]any); ok {
209-
for i, v := range arr {
210-
arr[i] = revive(strconv.Itoa(i), v, reviver)
209+
switch v := value.(type) {
210+
case []any:
211+
for i, el := range v {
212+
v[i] = revive(strconv.Itoa(i), el, reviver)
211213
}
212-
} else if m, ok := value.(map[string]any); ok {
213-
keys := make([]string, 0, len(m))
214-
for k := range m {
214+
case map[string]any:
215+
keys := make([]string, 0, len(v))
216+
for k := range v {
215217
keys = append(keys, k)
216218
}
217219
sort.Strings(keys)
218220
for _, k := range keys {
219-
m[k] = revive(k, m[k], reviver)
221+
v[k] = revive(k, v[k], reviver)
220222
}
221223
}
222224
return reviver(key, value)

0 commit comments

Comments
 (0)