Import path:
gitlab.soludian.com/soludian/fountain/libs/base/dump
dump
import "gitlab.soludian.com/soludian/fountain/libs/base/dump"Package dump like fmt.Println but more pretty and beautiful print Go values.
Index
- Constants
- func Clear(vs ...any)
- func Config(fns ...OptionFunc)
- func Format(vs ...any) string
- func Fprint(w io.Writer, vs ...any)
- func NoLoc(vs ...any)
- func P(vs ...any)
- func Print(vs ...any)
- func Println(vs ...any)
- func Reset()
- func Reset2()
- func V(vs ...any)
- type Dumper
- func NewDumper(out io.Writer, skip int) *Dumper
- func NewWithOptions(fns ...OptionFunc) *Dumper
- func Std() *Dumper
- func Std2() *Dumper
- func (d *Dumper) Dump(vs ...any)
- func (d *Dumper) Fprint(w io.Writer, vs ...any)
- func (d *Dumper) Print(vs ...any)
- func (d *Dumper) Println(vs ...any)
- func (d *Dumper) ResetOptions()
- func (d *Dumper) WithOptions(fns ...OptionFunc) *Dumper
- func (d *Dumper) WithSkip(skip int) *Dumper
- func (d *Dumper) WithoutColor() *Dumper
- type OptionFunc
- type Options
- type Theme
Constants
These flags define which print caller information
const (
KFlagNoPos = 1 << iota // no position
KFlagFunc
KFlagFile
KFlagFileName
KFlagLine
)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) stringFormat 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 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
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
type Dumper
Dumper struct definition
type Dumper struct {
*Options
// contains filtered or unexported fields
}func NewDumper
func NewDumper(out io.Writer, skip int) *DumperNewDumper create
func NewWithOptions
func NewWithOptions(fns ...OptionFunc) *DumperNewWithOptions create
func Std
func Std() *DumperStd dumper
func Std2
func Std2() *DumperStd2 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) *DumperWithOptions for dumper
func (*Dumper) WithSkip
func (d *Dumper) WithSkip(skip int) *DumperWithSkip for dumper
func (*Dumper) WithoutColor
func (d *Dumper) WithoutColor() *DumperWithoutColor for dumper
type OptionFunc
OptionFunc type
type OptionFunc func(opts *Options)func BytesAsString
func BytesAsString() OptionFuncBytesAsString setting.
func SkipNilField
func SkipNilField() OptionFuncSkipNilField setting.
func SkipPrivate
func SkipPrivate() OptionFuncSkipPrivate field dump on struct.
func WithCallerSkip
func WithCallerSkip(skip int) OptionFuncWithCallerSkip on print caller position information.
func WithoutColor
func WithoutColor() OptionFuncWithoutColor setting.
func WithoutOutput
func WithoutOutput(out io.Writer) OptionFuncWithoutOutput setting.
func WithoutPosition
func WithoutPosition() OptionFuncWithoutPosition dont print call dump position information.
func WithoutType
func WithoutType() OptionFuncWithoutType setting.
type Options
Options for dumper
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
func NewDefaultOptions(out io.Writer, skip int) *OptionsNewDefaultOptions create.
type Theme
Theme color code/tag map for dump
type Theme map[string]stringGenerated by gomarkdoc