Skip to content

Commit 8b055fb

Browse files
lvan100lianghuan
authored andcommitted
feat(flatten): refactor code
1 parent 3859c00 commit 8b055fb

9 files changed

Lines changed: 659 additions & 718 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ go.work.sum
3030
# Editor/IDE
3131
.idea/
3232
.vscode/
33+
.gocache/

flatten/flat.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func flattenValue(key string, val any, result map[string]string) {
9999
subValue := v.Index(i).Interface()
100100
flattenValue(subKey, subValue, result)
101101
}
102-
case reflect.Interface, reflect.Ptr:
102+
case reflect.Interface, reflect.Pointer:
103103
if v.IsNil() { // typed nil interface or pointer
104104
result[key] = "<nil>"
105105
return

flatten/path.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package flatten
1818

1919
import (
20+
"fmt"
2021
"strconv"
2122
"strings"
2223

@@ -32,6 +33,18 @@ const (
3233
PathTypeIndex // A numeric index in a list.
3334
)
3435

36+
// String returns the string representation of PathType.
37+
func (t PathType) String() string {
38+
switch t {
39+
case PathTypeKey:
40+
return "key"
41+
case PathTypeIndex:
42+
return "index"
43+
default:
44+
return fmt.Sprintf("PathType(%d)", int8(t))
45+
}
46+
}
47+
3548
// Path represents a single segment in a parsed key path.
3649
// A path is composed of multiple Path elements that can be joined or split.
3750
// For example, "foo.bar[0]" parses into:

0 commit comments

Comments
 (0)