| 1 |
package koanf |
| 2 |
|
| 3 |
// options contains options to modify the behavior of Koanf.Load. |
| 4 |
type options struct { |
| 5 |
merge func(a, b map[string]any) error |
| 6 |
} |
| 7 |
|
| 8 |
// newOptions creates a new options instance. |
| 9 |
func newOptions(opts []Option) *options { |
| 10 |
o := new(options) |
| 11 |
o.apply(opts) |
| 12 |
return o |
| 13 |
} |
| 14 |
|
| 15 |
// Option is a generic type used to modify the behavior of Koanf.Load. |
| 16 |
type Option func(*options) |
| 17 |
|
| 18 |
// apply the given options. |
| 19 |
func (o *options) apply(opts []Option) { |
| 20 |
for _, opt := range opts { |
| 21 |
opt(o) |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
// WithMergeFunc is an option to modify the merge behavior of Koanf.Load. |
| 26 |
// If unset, the default merge function is used. |
| 27 |
// |
| 28 |
// The merge function is expected to merge map src into dest (left to right). |
| 29 |
func WithMergeFunc(merge func(src, dest map[string]any) error) Option { |
| 30 |
return func(o *options) { |
| 31 |
o.merge = merge |
| 32 |
} |
| 33 |
} |