dump

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2019 License: MIT Imports: 12 Imported by: 0

README

XGo/dump

Quick Look

aInt := 1
bStr := `sf`
cMap := map[string]interface{}{"name": "z", "age": 14}
dArray := []interface{}{&cMap, aInt, bStr}

dump.Dump(aInt, &aInt, &bStr, bStr, cMap, dArray, cMap["name"], dArray[2], dArray[aInt])

Usage

a := 1

// use default instance
dump.Dump(a)

// new instance
c := dump.NewCliDumper()
c.Dump(a)

// 自定义 out
buf := &bytes.Buffer{}
dump.NewCliDumper(dump.OptOut(buf))

Option

自定义选项

// 全局禁用
// 可以在生产环境使用该选项避免意外
dump.Disable = true

// 显示代码位置
dump.ShowFileLine1 = true
dump.MarginLine1   = 36     // 显示行号时,前面可以加空格

// 自定义输出
dump.DefaultWriter = os.Stdout

// 数组最多显示多少个,其余的会省略为“...”
dump.MaxSliceLen = 32
dump.MaxMapLen   = 32

More TestCases

https://github.com/Kretech/xgo/blob/master/dump/cli_dumper_test.go

Documentation

Index

Constants

View Source
const (
	Zero = `<zero>`
	Nil  = "<nil>"
)

Variables

View Source
var (
	DefaultWriter io.Writer = os.Stdout

	// 显示对应代码位置
	ShowFileLine1 = false
	MarginLine1   = 36
)
View Source
var (
	// uint8(97) => 'a'
	OptShowUint8AsByte = false

	OptSortMapKeys = true
)
View Source
var (
	MaxSliceLen = 32
	MaxMapLen   = 32

	SepKv = " => "

	StringQuota = `"`
)
View Source
var (
	// disable dump in global scope
	// use it in production
	Disable = false
)

Functions

func Dump

func Dump(args ...interface{})

func IsScalar

func IsScalar(v interface{}) bool

IsScalar 简单类型

func Serialize added in v0.3.0

func Serialize(originValue interface{}) (serialized string)

Types

type CliDumper

type CliDumper struct {
	// contains filtered or unexported fields
}

func NewCliDumper

func NewCliDumper(opts ...Opt) *CliDumper

NewCliDumper

func (*CliDumper) DepthDump

func (c *CliDumper) DepthDump(depth int, args ...interface{})

func (*CliDumper) Dump

func (c *CliDumper) Dump(args ...interface{})

type Dumper

type Dumper interface {
	Dump(args ...interface{})
	DepthDump(depth int, args ...interface{})
}

type Opt

type Opt func(*CliDumper)

func OptOut

func OptOut(w io.Writer) Opt

Jump to

Keyboard shortcuts

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