pretty
packagemoduleThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
README¶
package pretty import "github.com/kr/pretty" Package pretty provides pretty-printing for Go values.Documentation http://godoc.org/github.com/kr/pretty
Documentation¶
Overview¶
Package pretty provides pretty-printing for Go values. This isuseful during debugging, to avoid wrapping long output lines inthe terminal.
It provides a function, Formatter, that can be used with anyfunction that accepts a format string. It also providesconvenience wrappers for functions in packages fmt and log.
Example¶
package mainimport ("fmt""github.com/kr/pretty")func main() {type myType struct {a, b int}var x = []myType{{1, 2}, {3, 4}, {5, 6}}fmt.Printf("%# v", pretty.Formatter(x))}
Output:[]pretty_test.myType{ {a:1, b:2}, {a:3, b:4}, {a:5, b:6},}
Index¶
- func Diff(a, b interface{}) (desc []string)
- func Errorf(format string, a ...interface{}) error
- func Fdiff(w io.Writer, a, b interface{})
- func Formatter(x interface{}) (f fmt.Formatter)
- func Fprintf(w io.Writer, format string, a ...interface{}) (n int, error error)
- func Ldiff(l Logfer, a, b interface{})
- func Log(a ...interface{})
- func Logf(format string, a ...interface{})
- func Logln(a ...interface{})
- func Pdiff(p Printfer, a, b interface{})
- func Print(a ...interface{}) (n int, errno error)
- func Printf(format string, a ...interface{}) (n int, errno error)
- func Println(a ...interface{}) (n int, errno error)
- func Sprint(a ...interface{}) string
- func Sprintf(format string, a ...interface{}) string
- type Logfer
- type Printfer
Examples¶
Constants¶
This section is empty.
Variables¶
This section is empty.
Functions¶
funcDiff¶
func Diff(a, b interface{}) (desc []string)
Diff returns a slice where each element describesa difference between a and b.
funcErrorf¶
Errorf is a convenience wrapper for fmt.Errorf.
Calling Errorf(f, x, y) is equivalent tofmt.Errorf(f, Formatter(x), Formatter(y)).
funcFormatter¶
Formatter makes a wrapper, f, that will format x as go source with linebreaks and tabs. Object f responds to the "%v" formatting verb when both the"#" and " " (space) flags are set, for example:
fmt.Sprintf("%# v", Formatter(x))
If one of these two flags is not set, or any other verb is used, f willformat x according to the usual rules of package fmt.In particular, if x satisfies fmt.Formatter, then x.Format will be called.
funcFprintf¶
Fprintf is a convenience wrapper for fmt.Fprintf.
Calling Fprintf(w, f, x, y) is equivalent tofmt.Fprintf(w, f, Formatter(x), Formatter(y)).
funcLdiff¶
func Ldiff(lLogfer, a, b interface{})
Ldiff prints to l a description of the differences between a and b.It calls Logf once for each difference, with no trailing newline.The standard library testing.T and testing.B are Logfers.
funcLog¶
func Log(a ...interface{})
Log is a convenience wrapper for log.Printf.
Calling Log(x, y) is equivalent tolog.Print(Formatter(x), Formatter(y)), but each operand isformatted with "%# v".
funcLogf¶
func Logf(formatstring, a ...interface{})
Logf is a convenience wrapper for log.Printf.
Calling Logf(f, x, y) is equivalent tolog.Printf(f, Formatter(x), Formatter(y)).
funcLogln¶
func Logln(a ...interface{})
Logln is a convenience wrapper for log.Printf.
Calling Logln(x, y) is equivalent tolog.Println(Formatter(x), Formatter(y)), but each operand isformatted with "%# v".
funcPdiff¶
func Pdiff(pPrintfer, a, b interface{})
Pdiff prints to p a description of the differences between a and b.It calls Printf once for each difference, with no trailing newline.The standard library log.Logger is a Printfer.
funcPrint¶
Print pretty-prints its operands and writes to standard output.
Calling Print(x, y) is equivalent tofmt.Print(Formatter(x), Formatter(y)), but each operand isformatted with "%# v".
funcPrintf¶
Printf is a convenience wrapper for fmt.Printf.
Calling Printf(f, x, y) is equivalent tofmt.Printf(f, Formatter(x), Formatter(y)).
funcPrintln¶
Println pretty-prints its operands and writes to standard output.
Calling Println(x, y) is equivalent tofmt.Println(Formatter(x), Formatter(y)), but each operand isformatted with "%# v".