-
Notifications
You must be signed in to change notification settings - Fork 191
/
options.go
115 lines (102 loc) · 2.18 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package dump
import (
"io"
"os"
)
// 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
// MoreLenNL array/slice elements length > MoreLenNL, will wrap new line
// MoreLenNL int
}
// OptionFunc type
type OptionFunc func(opts *Options)
// NewDefaultOptions create.
func NewDefaultOptions(out io.Writer, skip int) *Options {
if out == nil {
out = os.Stdout
}
return &Options{
Output: out,
// ---
MaxDepth: 5,
ShowFlag: Ffunc | Ffname | Fline,
// MoreLenNL: 8,
// ---
IndentLen: 2,
IndentChar: ' ',
CallerSkip: skip,
ColorTheme: defaultTheme,
}
}
// SkipNilField setting.
func SkipNilField() OptionFunc {
return func(opt *Options) {
opt.SkipNilField = true
}
}
// SkipPrivate field dump on struct.
func SkipPrivate() OptionFunc {
return func(opt *Options) {
opt.SkipPrivate = true
}
}
// BytesAsString setting.
func BytesAsString() OptionFunc {
return func(opt *Options) {
opt.BytesAsString = true
}
}
// WithCallerSkip on print caller position information.
func WithCallerSkip(skip int) OptionFunc {
return func(opt *Options) {
opt.CallerSkip = skip
}
}
// WithoutPosition dont print call dump position information.
func WithoutPosition() OptionFunc {
return func(opt *Options) {
opt.ShowFlag = Fnopos
}
}
// WithoutOutput setting.
func WithoutOutput(out io.Writer) OptionFunc {
return func(opt *Options) {
opt.Output = out
}
}
// WithoutColor setting.
func WithoutColor() OptionFunc {
return func(opt *Options) {
opt.NoColor = true
}
}
// WithoutType setting.
func WithoutType() OptionFunc {
return func(opt *Options) {
opt.NoType = true
}
}