Skip to content

Commit 2084c37

Browse files
committed
handled nil pointer
1 parent b7c72f0 commit 2084c37

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

godump.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,15 @@ func printValue(tw *tabwriter.Writer, v reflect.Value, indent int, visited map[u
232232
fmt.Fprintln(tw)
233233
visibleFields := reflect.VisibleFields(t)
234234
for _, field := range visibleFields {
235+
//handle nil pointer
236+
if field.Anonymous && v.FieldByIndex(field.Index).Kind() == reflect.Ptr && v.FieldByIndex(field.Index).IsNil() {
237+
indentPrint(tw, indent+1, colorize(colorYellow, "+"+field.Name))
238+
fmt.Fprint(tw, " => ")
239+
fmt.Fprint(tw, colorize(colorGray, "<nil embedded>"))
240+
fmt.Fprintln(tw)
241+
continue
242+
}
243+
235244
fieldVal := v.FieldByIndex(field.Index)
236245
symbol := "+"
237246
if field.PkgPath != "" {

0 commit comments

Comments
 (0)