-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
53 lines (45 loc) · 1.16 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
package flat
const (
// Default delimiter used if none is specified
DefaultDelimiter string = "."
)
// Options allows customization of input and output behavior
type Options struct {
// Delimiter used for key concatenation
Delimiter string
// Function for modifying keys (optional)
Fold func(string) string
}
// DefaultOptions creates an option object with default values.
func DefaultOptions(opts ...func(options *Options)) *Options {
options := &Options{
Delimiter: DefaultDelimiter,
Fold: func(s string) string { return s },
}
for _, opt := range opts {
if opt != nil {
opt(options)
}
}
return options
}
// WithOptions sets custom options for input and output behavior.
func WithOptions(options *Options) func(o *Options) {
return func(o *Options) {
if options != nil {
*o = *options
}
}
}
// WithDelimiter sets a custom delimiter for key concatenation.
func WithDelimiter(delimiter string) func(o *Options) {
return func(o *Options) {
o.Delimiter = delimiter
}
}
// WithFold sets a custom function for modifying keys (optional).
func WithFold(fold func(string) string) func(o *Options) {
return func(o *Options) {
o.Fold = fold
}
}