fix: do not allow overwriting the mapstructure output

Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
This commit is contained in:
Mark Sagi-Kazar 2024-06-24 18:14:40 +02:00
parent 35a46059e3
commit 9a962379e6
No known key found for this signature in database
GPG key ID: 31AB0439F4C5C90E

View file

@ -945,7 +945,6 @@ func (v *Viper) decodeStructKeys(input any, opts ...DecoderConfigOption) ([]stri
func defaultDecoderConfig(output any, opts ...DecoderConfigOption) *mapstructure.DecoderConfig {
c := &mapstructure.DecoderConfig{
Metadata: nil,
Result: output,
WeaklyTypedInput: true,
DecodeHook: mapstructure.ComposeDecodeHookFunc(
mapstructure.StringToTimeDurationHookFunc(),
@ -953,9 +952,14 @@ func defaultDecoderConfig(output any, opts ...DecoderConfigOption) *mapstructure
stringToWeakSliceHookFunc(","),
),
}
for _, opt := range opts {
opt(c)
}
// Do not allow overwriting the output
c.Result = output
return c
}