Documentation
¶
Overview ¶
Package reveal is a deep pretty printer for Go data structures.
It is a modern, maintained, and bug-fixed replacement for github.com/davecgh/go-spew. The API is fully compatible with go-spew — change the import path and everything works.
Basic usage:
reveal.Dump(myStruct) // print to stdout s := reveal.Sdump(myStruct) // return as string reveal.Fdump(w, myStruct) // print to io.Writer
Configuration:
config := reveal.Config config.MaxDepth = 5 config.Dump(myStruct)
Index ¶
- Variables
- func Dump(a ...interface{})
- func Fdump(w io.Writer, a ...interface{})
- func Fprint(w io.Writer, a ...interface{}) (int, error)
- func Fprintf(w io.Writer, format string, a ...interface{}) (int, error)
- func Fprintln(w io.Writer, a ...interface{}) (int, error)
- func NewFormatter(v interface{}) fmt.Formatter
- func Printf(format string, a ...interface{}) (int, error)
- func Println(a ...interface{}) (int, error)
- func Sdump(a ...interface{}) string
- func Sprint(a ...interface{}) string
- func Sprintf(format string, a ...interface{}) string
- func Sprintln(a ...interface{}) string
- type ConfigState
- func (c *ConfigState) Dump(a ...interface{})
- func (c *ConfigState) Fdump(w io.Writer, a ...interface{})
- func (c *ConfigState) Fprint(w io.Writer, a ...interface{}) (int, error)
- func (c *ConfigState) Fprintf(w io.Writer, format string, a ...interface{}) (int, error)
- func (c *ConfigState) Fprintln(w io.Writer, a ...interface{}) (int, error)
- func (c *ConfigState) NewFormatter(v interface{}) fmt.Formatter
- func (c *ConfigState) Sdump(a ...interface{}) string
- func (c *ConfigState) Sprint(a ...interface{}) string
- func (c *ConfigState) Sprintf(format string, a ...interface{}) string
- func (c *ConfigState) Sprintln(a ...interface{}) string
Constants ¶
This section is empty.
Variables ¶
var Config = ConfigState{ Indent: " ", MaxSize: 10 * 1024 * 1024, RecoverPanics: true, }
Config is the active default configuration for reveal. Modify this to change the default behavior of package-level functions.
Functions ¶
func Dump ¶
func Dump(a ...interface{})
Dump displays the passed parameters to standard output with type info, pointer addresses, and nested structure. It uses the default configuration.
func Fdump ¶
Fdump formats and writes the passed parameters to the given io.Writer. It uses the default configuration.
func NewFormatter ¶
NewFormatter returns a fmt.Formatter that formats the given value using reveal. The returned Formatter supports the following verbs:
%v — inline format (same as fmt %v but with deep traversal) %+v — inline format with field names (for structs) %#v — Go-syntax representation %d — dump format (same as Dump output)
Use it with fmt.Sprintf, fmt.Fprintf, etc:
fmt.Sprintf("%v", reveal.NewFormatter(myStruct))
func Sdump ¶
func Sdump(a ...interface{}) string
Sdump returns a string with the passed parameters formatted using Dump style. It uses the default configuration.
func Sprint ¶
func Sprint(a ...interface{}) string
Sprint is a deep-aware replacement for fmt.Sprint.
Types ¶
type ConfigState ¶
type ConfigState struct {
// Indent specifies the string to use for each indentation level. Default: " " (single space).
Indent string
// MaxDepth controls the maximum depth to recurse into nested types. 0 means unlimited.
MaxDepth int
// DisableMethods disables invocation of error and Stringer interface methods.
DisableMethods bool
// DisablePointerMethods disables invocation of error and Stringer interface
// methods on pointer receivers. This only applies when DisableMethods is false.
DisablePointerMethods bool
// DisablePointerAddresses disables printing of pointer addresses.
DisablePointerAddresses bool
// DisableCapacities disables printing of capacities for arrays, slices, and maps.
DisableCapacities bool
// ContinueOnMethod causes the dump to continue after calling a Stringer/Error method,
// showing the internal structure as well.
ContinueOnMethod bool
// SortKeys causes map keys to be sorted before printing to produce deterministic output.
SortKeys bool
// SpewKeys causes map keys to be formatted using the Dump format for the key.
SpewKeys bool
// MaxSize is the maximum number of bytes the output may be. 0 means unlimited.
// Default: 10485760 (10 MB). Prevents memory exhaustion with deeply nested structures.
MaxSize int
// RecoverPanics causes reveal to recover from panics in Stringer/Error methods
// and fall back to raw value dumping. Default: true.
RecoverPanics bool
// OmitNilPointers suppresses nil pointer fields in struct output.
OmitNilPointers bool
// OmitUnexported suppresses unexported struct fields from output.
OmitUnexported bool
// HexIntegers formats integer values in hexadecimal.
HexIntegers bool
}
ConfigState holds the configuration options for reveal. All go-spew compatible fields are supported, plus additional reveal-only fields.
func (*ConfigState) Dump ¶
func (c *ConfigState) Dump(a ...interface{})
Dump displays the passed parameters to standard output with type info, pointer addresses, and nested structure using the configuration options in c.
func (*ConfigState) Fdump ¶
func (c *ConfigState) Fdump(w io.Writer, a ...interface{})
Fdump formats and writes the passed parameters to the given io.Writer.
func (*ConfigState) Fprint ¶
func (c *ConfigState) Fprint(w io.Writer, a ...interface{}) (int, error)
Fprint is a deep-aware replacement for fmt.Fprint.
func (*ConfigState) Fprintln ¶
func (c *ConfigState) Fprintln(w io.Writer, a ...interface{}) (int, error)
Fprintln is a deep-aware replacement for fmt.Fprintln.
func (*ConfigState) NewFormatter ¶
func (c *ConfigState) NewFormatter(v interface{}) fmt.Formatter
NewFormatter returns a fmt.Formatter bound to this ConfigState.
func (*ConfigState) Sdump ¶
func (c *ConfigState) Sdump(a ...interface{}) string
Sdump returns a string with the passed parameters formatted using Dump style.
func (*ConfigState) Sprint ¶
func (c *ConfigState) Sprint(a ...interface{}) string
Sprint is a deep-aware replacement for fmt.Sprint. Each argument is formatted using reveal's dump traversal.
func (*ConfigState) Sprintf ¶
func (c *ConfigState) Sprintf(format string, a ...interface{}) string
Sprintf is a deep-aware replacement for fmt.Sprintf. Arguments referenced by format verbs are formatted using reveal's deep traversal.
func (*ConfigState) Sprintln ¶
func (c *ConfigState) Sprintln(a ...interface{}) string
Sprintln is a deep-aware replacement for fmt.Sprintln.