format

package module
v0.0.0-...-e734481 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2024 License: MIT Imports: 8 Imported by: 0

README

format

formatting go values

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fprint

func Fprint(w io.Writer, x any) error

Fprint calls Formatter.Fprint with the default Formatter.

func Print

func Print(x any) error

Print calls Formatter.Print with the default Formatter.

func Sprint

func Sprint(x any) string

Sprint calls Formatter.Sprint with the default Formatter.

Types

type Formatter

type Formatter struct {
	// ShowUnexported bool   // display unexported fields
	ShowZero    bool   // display struct fields that have their zero value
	MaxWidth    int    // maximum columns, but not breaking words
	Compact     bool   // as few lines as possible, observing MaxWidth
	Indent      string // ignored if Compact; default is 4 spaces
	MaxDepth    int    // max recursion depth; default is 100
	MaxElements int    // max array, slice or map elements to print
	OmitPackage bool   // don't print package in type names
	// contains filtered or unexported fields
}

A Formatter formats Go values. It follows pointers recursively, detecting cycles. Configure a Formatter by setting the exported fields before calling a formatting method. The defaults are designed to work well in tests.

func New

func New() *Formatter

New returns a new default Formatter.

func (*Formatter) Fprint

func (f *Formatter) Fprint(w io.Writer, x any) error

Fprint formats x and writes to w.

func (*Formatter) IgnoreFields

func (f *Formatter) IgnoreFields(structval any, fields ...string) *Formatter

IgnoreFields causes f to skip printing of the named fields of values of structval's type. Structval must be a struct or a pointer to a struct. It returns its receiver.

func (*Formatter) Print

func (f *Formatter) Print(x any) error

Print formats x and writes to the standard output.

func (*Formatter) Sprint

func (f *Formatter) Sprint(x any) string

Sprint formats x and returns a string.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL