dump

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2022 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])

Option

custom options

// disable dump in global, default false means enable
// disable it in production to ignore the unnecessary output and risks
dump.Disable = false

// show variant line in head
dump.ShowFileLine1 = true

// change writer in global
dump.DefaultWriter = os.Stdout

// only show the first-n elements
// others will show as '...'
// * these options is design for debug clearly
dump.MaxSliceLen = 32
dump.MaxMapLen   = 32

// serialize options

// render map with sorted keys
dump.OptSortMapKeys = true

// render []uint8(`ab`) as string("ab")
OptShowUint8sAsString = true

// render uint8(97) as char('a')
OptShowUint8AsChar

More TestCases

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

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

Documentation

Index

Constants

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

Variables

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

	// 显示对应代码位置
	ShowFileLine1 = true
)
View Source
var (
	// uint8(97) => 'a'
	OptShowUint8AsChar = true

	// []uint8{'a','b'} => "ab"
	OptShowUint8sAsString = true

	// 按字典序显示map.keys
	OptSortMapKeys = true
)
View Source
var (
	MaxSliceLen = 32
	MaxMapLen   = 32

	SepKv = " => "

	StringQuota = `"`
)
View Source
var Disable = false

disable dump in global scope use it in production

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(X string) CliDumper

func (CliDumper) DepthDump

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

func (CliDumper) Dump

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

Jump to

Keyboard shortcuts

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