Movatterモバイル変換


[0]ホーム

URL:


pretty

packagemodule
v0.3.1Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2022 License:MITImports:8Imported by:3,144

Details

Repository

github.com/kr/pretty

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

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

func Errorf(formatstring, a ...interface{})error

Errorf is a convenience wrapper for fmt.Errorf.

Calling Errorf(f, x, y) is equivalent tofmt.Errorf(f, Formatter(x), Formatter(y)).

funcFdiff

func Fdiff(wio.Writer, a, b interface{})

Fdiff writes to w a description of the differences between a and b.

funcFormatter

func Formatter(x interface{}) (ffmt.Formatter)

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

func Fprintf(wio.Writer, formatstring, a ...interface{}) (nint, errorerror)

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

func Print(a ...interface{}) (nint, errnoerror)

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

func Printf(formatstring, a ...interface{}) (nint, errnoerror)

Printf is a convenience wrapper for fmt.Printf.

Calling Printf(f, x, y) is equivalent tofmt.Printf(f, Formatter(x), Formatter(y)).

funcPrintln

func Println(a ...interface{}) (nint, errnoerror)

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".

funcSprint

func Sprint(a ...interface{})string

Sprint is a convenience wrapper for fmt.Sprintf.

Calling Sprint(x, y) is equivalent tofmt.Sprint(Formatter(x), Formatter(y)), but each operand isformatted with "%# v".

funcSprintf

func Sprintf(formatstring, a ...interface{})string

Sprintf is a convenience wrapper for fmt.Sprintf.

Calling Sprintf(f, x, y) is equivalent tofmt.Sprintf(f, Formatter(x), Formatter(y)).

Types

typeLogfer

type Logfer interface {Logf(formatstring, a ...interface{})}

typePrintfer

type Printfer interface {Printf(formatstring, a ...interface{})}

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp