dump

package
v0.0.0-...-754e97a Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2020 License: MIT Imports: 10 Imported by: 0

README

Dump

This is an print debug vars util package.

Install

go get github.com/gookit/goutil/dump

Usage

run demo: go run ./dump/_examples/demo1.go

package main

import "github.com/gookit/goutil/dump"

// rum demo: go run ./dump/_examples/demo1.go
func main() {
	otherFunc1()
}

func otherFunc1() {
	dump.P(
		23,
		[]string{"ab", "cd"},
		[]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, // len > 10
		map[string]interface{}{
			"key": "val", "sub": map[string]string{"k": "v"},
		},
		struct {
			ab string
			Cd int
		}{
			"ab", 23,
		},
	)
}

You will see:

More preview

  • nested struct

Functions

func P(vs ...interface{})
func V(vs ...interface{})
func Print(vs ...interface{})

Documentation

Overview

Package dump like fmt.Println but more clear and beautiful print data.

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 Config

func Config(fn func(*Dumper))

Config std dumper

func Fprint

func Fprint(w io.Writer, vs ...interface{})

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

func P

func P(vs ...interface{})

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

func Print

func Print(vs ...interface{})

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

Example
Config(func(d *Dumper) {
	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]interface{}{
		"sub": map[string]string{"k": "v"},
	},
	struct {
		ab string
		Cd int
	}{
		"ab", 23,
	},
)

// Output like:
// PRINT AT gitee.com/ckbabby/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 ...interface{})

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

func Reset

func Reset()

Reset std dumper

func V

func V(vs ...interface{})

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

Types

type Dumper

type Dumper struct {
	Options
	Output io.Writer
	// Skip for call runtime.Caller()
	Skip int
	// contains filtered or unexported fields
}

Dumper struct

func NewDumper

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

NewDumper create

func Std

func Std() *Dumper

Std dumper

func (*Dumper) Config

func (d *Dumper) Config(fn func(d *Dumper)) *Dumper

Config for dumper

func (*Dumper) Dump

func (d *Dumper) Dump(vars ...interface{})

Dump vars

func (*Dumper) Fprint

func (d *Dumper) Fprint(w io.Writer, vars ...interface{})

Fprint print vars to io.Writer

func (*Dumper) Print

func (d *Dumper) Print(vars ...interface{})

Print vars. alias of Dump()

func (*Dumper) Println

func (d *Dumper) Println(vars ...interface{})

Println vars. alias of Dump()

func (*Dumper) ResetOptions

func (d *Dumper) ResetOptions()

ResetOptions for dumper

func (*Dumper) WithOptions

func (d *Dumper) WithOptions(opts Options) *Dumper

WithOptions for dumper

func (*Dumper) WithSkip

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

WithSkip for dumper

type Options

type Options struct {
	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
	// MoreLenNL array/slice elements length > MoreLenNL, will wrap new line
	MoreLenNL int
}

Options for dump vars

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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