Feat: add DisableUnexported
DisableUnexported specifies whether to disable the unexported fields of struct. This is useful for debugging APIs.
This commit is contained in:
parent
d8f796af33
commit
f366af591d
|
@ -76,6 +76,10 @@ type ConfigState struct {
|
||||||
// data structures in tests.
|
// data structures in tests.
|
||||||
DisableCapacities bool
|
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
|
// ContinueOnMethod specifies whether or not recursion should continue once
|
||||||
// a custom error or Stringer interface is invoked. The default, false,
|
// a custom error or Stringer interface is invoked. The default, false,
|
||||||
// means it will print the results of invoking the custom error or Stringer
|
// means it will print the results of invoking the custom error or Stringer
|
||||||
|
|
|
@ -26,6 +26,7 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"unicode"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -413,8 +414,11 @@ func (d *dumpState) dump(v reflect.Value) {
|
||||||
vt := v.Type()
|
vt := v.Type()
|
||||||
numFields := v.NumField()
|
numFields := v.NumField()
|
||||||
for i := 0; i < numFields; i++ {
|
for i := 0; i < numFields; i++ {
|
||||||
d.indent()
|
|
||||||
vtf := vt.Field(i)
|
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([]byte(vtf.Name))
|
||||||
d.w.Write(colonSpaceBytes)
|
d.w.Write(colonSpaceBytes)
|
||||||
d.ignoreNextIndent = true
|
d.ignoreNextIndent = true
|
||||||
|
|
Loading…
Reference in New Issue