dump

package
v1.0.38 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package dump like fmt.Println but more pretty and beautiful print Go values.

Index

Examples

Constants

View Source
const (
	Fnopos = 1 << iota // no position
	Ffunc
	Ffile
	Ffname
	Fline
)

These flags define which print caller information

Variables

This section is empty.

Functions

func Clear

func Clear(vs ...any)

Clear dump clear data, without location.

func Config

func Config(fns ...OptionFunc)

Config std dumper

func Format

func Format(vs ...any) string

Format like fmt.Println, but the output is clearer and more beautiful

func Fprint

func Fprint(w io.Writer, vs ...any)

Fprint like fmt.Println, but the output is clearer and more beautiful

func NoLoc

func NoLoc(vs ...any)

NoLoc dump vars data, without location.

func P

func P(vs ...any)

P like fmt.Println, but the output is clearer and more beautiful

func Print

func Print(vs ...any)

Print like fmt.Println, but the output is clearer and more beautiful

Example
Config(func(d *Options) {
	d.NoColor = true
})
defer Reset()

Print(
	23,
	[]string{"ab", "cd"},
	[]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
	map[string]string{"key": "val"},
	map[string]any{
		"sub": map[string]string{"k": "v"},
	},
	struct {
		ab string
		Cd int
	}{
		"ab", 23,
	},
)

// Output like:
// PRINT AT github.com/gookit/goutil/dump.ExamplePrint(LINE 14):
// int(23)
// []string{"ab", "cd"}
// []int [
//   1,
//   2,
//   3,
//   4,
//   5,
//   6,
//   7,
//   8,
//   9,
//   10,
//   11,
// ]
// map[string]string {
//   key: "val",
// }
// map[string]interface {} {
//   sub: map[string]string{"k":"v"},
// }
// struct { ab string; Cd int } {
//   ab: "ab",
//   Cd: 23,
// }
//
Output:

func Println

func Println(vs ...any)

Println like fmt.Println, but the output is clearer and more beautiful

func Reset

func Reset()

Reset std dumper

func Reset2

func Reset2()

Reset2 reset std2 dumper

func V

func V(vs ...any)

V like fmt.Println, but the output is clearer and more beautiful

Types

type Dumper

type Dumper struct {
	*Options
	// contains filtered or unexported fields
}

Dumper struct definition

func NewDumper

func NewDumper(out io.Writer, skip int) *Dumper

NewDumper create

func NewWithOptions

func NewWithOptions(fns ...OptionFunc) *Dumper

NewWithOptions create

func Std

func Std() *Dumper

Std dumper

func Std2

func Std2() *Dumper

Std2 dumper

func (*Dumper) Dump

func (d *Dumper) Dump(vs ...any)

Dump vars

func (*Dumper) Fprint

func (d *Dumper) Fprint(w io.Writer, vs ...any)

Fprint print vars to io.Writer

func (*Dumper) Print

func (d *Dumper) Print(vs ...any)

Print vars. alias of Dump()

func (*Dumper) Println

func (d *Dumper) Println(vs ...any)

Println vars. alias of Dump()

func (*Dumper) ResetOptions

func (d *Dumper) ResetOptions()

ResetOptions for dumper

func (*Dumper) WithOptions

func (d *Dumper) WithOptions(fns ...OptionFunc) *Dumper

WithOptions for dumper

func (*Dumper) WithSkip

func (d *Dumper) WithSkip(skip int) *Dumper

WithSkip for dumper

func (*Dumper) WithoutColor

func (d *Dumper) WithoutColor() *Dumper

WithoutColor for dumper

type OptionFunc

type OptionFunc func(opts *Options)

OptionFunc type

func BytesAsString

func BytesAsString() OptionFunc

BytesAsString setting.

func SkipNilField

func SkipNilField() OptionFunc

SkipNilField setting.

func SkipPrivate

func SkipPrivate() OptionFunc

SkipPrivate field dump on struct.

func WithCallerSkip

func WithCallerSkip(skip int) OptionFunc

WithCallerSkip on print caller position information.

func WithoutColor

func WithoutColor() OptionFunc

WithoutColor setting.

func WithoutOutput

func WithoutOutput(out io.Writer) OptionFunc

WithoutOutput setting.

func WithoutPosition

func WithoutPosition() OptionFunc

WithoutPosition dont print call dump position information.

func WithoutType

func WithoutType() OptionFunc

WithoutType setting.

type Options

type Options struct {
	// Output the output writer
	Output io.Writer
	// NoType don't show data type TODO
	NoType bool
	// NoColor don't with color
	NoColor bool
	// IndentLen width. default is 2
	IndentLen int
	// IndentChar default is one space
	IndentChar byte
	// MaxDepth for nested print
	MaxDepth int
	// ShowFlag for display caller position
	ShowFlag int
	// CallerSkip skip for call runtime.Caller()
	CallerSkip int
	// ColorTheme for print result.
	ColorTheme Theme
	// SkipNilField value dump on map, struct.
	SkipNilField bool
	// SkipPrivate field dump on struct.
	SkipPrivate bool
	// BytesAsString dump handle.
	BytesAsString bool
}

Options for dumper

func NewDefaultOptions

func NewDefaultOptions(out io.Writer, skip int) *Options

NewDefaultOptions create.

type Theme

type Theme map[string]string

Theme color code/tag map for dump

Jump to

Keyboard shortcuts

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