Skip to content

Import path: gitlab.soludian.com/soludian/fountain/libs/base/dump

dump

go
import "gitlab.soludian.com/soludian/fountain/libs/base/dump"

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

Index

Constants

These flags define which print caller information

go
const (
    KFlagNoPos = 1 << iota // no position
    KFlagFunc
    KFlagFile
    KFlagFileName
    KFlagLine
)

func Clear

go
func Clear(vs ...any)

Clear dump clear data, without location.

func Config

go
func Config(fns ...OptionFunc)

Config std dumper

func Format

go
func Format(vs ...any) string

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

func Fprint

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

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

func NoLoc

go
func NoLoc(vs ...any)

NoLoc dump vars data, without location.

func P

go
func P(vs ...any)

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

func Print

go
func Print(vs ...any)

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

Example

go
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 gitlab.soludian.com/soludian/fountain/libs/base/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,
// }
//

func Println

go
func Println(vs ...any)

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

func Reset

go
func Reset()

Reset std dumper

func Reset2

go
func Reset2()

Reset2 reset std2 dumper

func V

go
func V(vs ...any)

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

type Dumper

Dumper struct definition

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

func NewDumper

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

NewDumper create

func NewWithOptions

go
func NewWithOptions(fns ...OptionFunc) *Dumper

NewWithOptions create

func Std

go
func Std() *Dumper

Std dumper

func Std2

go
func Std2() *Dumper

Std2 dumper

func (*Dumper) Dump

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

Dump vars

func (*Dumper) Fprint

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

Fprint print vars to io.Writer

func (*Dumper) Print

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

Print vars. alias of Dump()

func (*Dumper) Println

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

Println vars. alias of Dump()

func (*Dumper) ResetOptions

go
func (d *Dumper) ResetOptions()

ResetOptions for dumper

func (*Dumper) WithOptions

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

WithOptions for dumper

func (*Dumper) WithSkip

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

WithSkip for dumper

func (*Dumper) WithoutColor

go
func (d *Dumper) WithoutColor() *Dumper

WithoutColor for dumper

type OptionFunc

OptionFunc type

go
type OptionFunc func(opts *Options)

func BytesAsString

go
func BytesAsString() OptionFunc

BytesAsString setting.

func SkipNilField

go
func SkipNilField() OptionFunc

SkipNilField setting.

func SkipPrivate

go
func SkipPrivate() OptionFunc

SkipPrivate field dump on struct.

func WithCallerSkip

go
func WithCallerSkip(skip int) OptionFunc

WithCallerSkip on print caller position information.

func WithoutColor

go
func WithoutColor() OptionFunc

WithoutColor setting.

func WithoutOutput

go
func WithoutOutput(out io.Writer) OptionFunc

WithoutOutput setting.

func WithoutPosition

go
func WithoutPosition() OptionFunc

WithoutPosition dont print call dump position information.

func WithoutType

go
func WithoutType() OptionFunc

WithoutType setting.

type Options

Options for dumper

go
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
}

func NewDefaultOptions

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

NewDefaultOptions create.

type Theme

Theme color code/tag map for dump

go
type Theme map[string]string

Generated by gomarkdoc