Documentation
¶
Overview ¶
Package repr attempts to represent Go values in a form that can be copy-and-pasted into source code directly.
Some values (such as pointers to basic types) can not be represented directly in Go. These values will be output as `&<value>`. eg. `&23`
Index ¶
- Variables
- func Print(vs ...any)
- func Println(vs ...any)
- func String(v any, options ...Option) string
- type Option
- func AlwaysIncludeType() Option
- func ExplicitTypes(ok bool) Option
- func Hide[T any]() Option
- func HideField(name string) Option
- func IgnoreGoStringer() Option
- func IgnorePrivate() Option
- func Indent(indent string) Option
- func NoIndent() Option
- func OmitEmpty(omitEmpty bool) Option
- func OmitZero(omitZero bool) Option
- func ScalarLiterals() Option
- type Printer
Constants ¶
This section is empty.
Variables ¶
var Default = New(os.Stdout, Indent(" "))
Default prints to os.Stdout with two space indentation.
Functions ¶
Types ¶
type Option ¶
type Option func(o *Printer)
An Option modifies the default behaviour of a Printer.
func AlwaysIncludeType ¶
func AlwaysIncludeType() Option
AlwaysIncludeType always includes explicit type information for each item.
func ExplicitTypes ¶
ExplicitTypes adds explicit typing to slice and map struct values that would normally be inferred by Go.
func HideField ¶ added in v0.5.0
HideField excludes fields of structs that match the given name from representation.
func IgnoreGoStringer ¶
func IgnoreGoStringer() Option
IgnoreGoStringer disables use of the .GoString() method.
func IgnorePrivate ¶ added in v0.3.0
func IgnorePrivate() Option
IgnorePrivate disables private field members from output.
func OmitEmpty ¶
OmitEmpty sets whether empty field members should be omitted from output.
Empty field members are either the zero type, or zero-length maps and slices.
func OmitZero ¶ added in v0.5.0
OmitZero sets whether zero field members should be omitted from output.
Field members are considered zero if they have an IsZero method that returns true, or if reflect.Value.IsZero returns true. Empty maps and slices are not zero.
func ScalarLiterals ¶ added in v0.3.0
func ScalarLiterals() Option
ScalarLiterals forces the use of literals for scalars, rather than a string representation if available.
For example, `time.Hour` will be printed as `time.Duration(3600000000000)` rather than `time.Duration(1h0m0s)`.