pretty

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2025 License: MIT Imports: 9 Imported by: 2 modules, 4 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 is useful during debugging, to avoid wrapping long output lines in the terminal.

It provides a function, Formatter, that can be used with any function that accepts a format string. It also provides convenience wrappers for functions in packages fmt and log.

Example
package main

import (
	"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

View Source
var ConvertErrorStringObject bool = false

Functions

func Diff

func Diff(a, b interface{}) (desc []string)

Diff returns a slice where each element describes a difference between a and b.

func Errorf

func Errorf(format string, a ...interface{}) error

Errorf is a convenience wrapper for fmt.Errorf.

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

func Fdiff

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

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

func Formatter

func Formatter(x interface{}) (f fmt.Formatter)

Formatter makes a wrapper, f, that will format x as go source with line breaks 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 will format x according to the usual rules of package fmt. In particular, if x satisfies fmt.Formatter, then x.Format will be called.

func Fprintf

func Fprintf(w io.Writer, format string, a ...interface{}) (n int, error error)

Fprintf is a convenience wrapper for fmt.Fprintf.

Calling Fprintf(w, f, x, y) is equivalent to fmt.Fprintf(w, f, Formatter(x), Formatter(y)).

func LazyFormatter

func LazyFormatter(x interface{}) (f fmt.Formatter)

LazyFormatter works like Formatter but does not print fields with zero values.

func LazyFprintf

func LazyFprintf(w io.Writer, format string, a ...interface{}) (n int, error error)

LazyFprintf works just like pretty.Fprintf but does not print fields with zero values.

func LazySprintf

func LazySprintf(format string, a ...interface{}) string

LazySprintf works just like pretty.Sprintf but does not print fields with zero values.

func Ldiff

func Ldiff(l Logfer, 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.

func Log

func Log(a ...interface{})

Log is a convenience wrapper for log.Printf.

Calling Log(x, y) is equivalent to log.Print(Formatter(x), Formatter(y)), but each operand is formatted with "%# v".

func Logf

func Logf(format string, a ...interface{})

Logf is a convenience wrapper for log.Printf.

Calling Logf(f, x, y) is equivalent to log.Printf(f, Formatter(x), Formatter(y)).

func Logln

func Logln(a ...interface{})

Logln is a convenience wrapper for log.Printf.

Calling Logln(x, y) is equivalent to log.Println(Formatter(x), Formatter(y)), but each operand is formatted with "%# v".

func Nonzero

func Nonzero(v reflect.Value) bool

func Pdiff

func Pdiff(p Printfer, 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.

func Print

func Print(a ...interface{}) (n int, errno error)

Print pretty-prints its operands and writes to standard output.

Calling Print(x, y) is equivalent to fmt.Print(Formatter(x), Formatter(y)), but each operand is formatted with "%# v".

func Printf

func Printf(format string, a ...interface{}) (n int, errno error)

Printf is a convenience wrapper for fmt.Printf.

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

func Println

func Println(a ...interface{}) (n int, errno error)

Println pretty-prints its operands and writes to standard output.

Calling Print(x, y) is equivalent to fmt.Println(Formatter(x), Formatter(y)), but each operand is formatted with "%# v".

func Sprint

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

Sprint is a convenience wrapper for fmt.Sprintf.

Calling Sprint(x, y) is equivalent to fmt.Sprint(Formatter(x), Formatter(y)), but each operand is formatted with "%# v".

func Sprintf

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

Sprintf is a convenience wrapper for fmt.Sprintf.

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

Types

type Logfer

type Logfer interface {
	Logf(format string, a ...interface{})
}

type Printfer

type Printfer interface {
	Printf(format string, a ...interface{})
}

Jump to

Keyboard shortcuts

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