Feat: add DisableUnexported

DisableUnexported specifies whether to disable the unexported fields of struct.
This is useful for debugging APIs.
This commit is contained in:
flw 2020-02-04 18:03:36 +08:00
parent d8f796af33
commit f366af591d
No known key found for this signature in database
GPG Key ID: C7CD7A7DE96BD7C2
2 changed files with 9 additions and 1 deletions

View File

@ -76,6 +76,10 @@ type ConfigState struct {
// data structures in tests.
DisableCapacities bool
// DisableUnexported specifies whether to disable the unexported fields of
// struct. This is useful for debugging APIs.
DisableUnexported bool
// ContinueOnMethod specifies whether or not recursion should continue once
// a custom error or Stringer interface is invoked. The default, false,
// means it will print the results of invoking the custom error or Stringer

View File

@ -26,6 +26,7 @@ import (
"regexp"
"strconv"
"strings"
"unicode"
)
var (
@ -413,8 +414,11 @@ func (d *dumpState) dump(v reflect.Value) {
vt := v.Type()
numFields := v.NumField()
for i := 0; i < numFields; i++ {
d.indent()
vtf := vt.Field(i)
if d.cs.DisableUnexported && !unicode.IsUpper([]rune(vtf.Name)[0]) {
continue
}
d.indent()
d.w.Write([]byte(vtf.Name))
d.w.Write(colonSpaceBytes)
d.ignoreNextIndent = true