fix: do not allow setting dependencies to nil values

Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
This commit is contained in:
Mark Sagi-Kazar 2024-06-24 18:06:28 +02:00 committed by Márk Sági-Kazár
parent 35a46059e3
commit 7dbe493dd1
3 changed files with 24 additions and 0 deletions

View file

@ -58,6 +58,10 @@ type CodecRegistry interface {
// WithEncoderRegistry sets a custom [EncoderRegistry].
func WithEncoderRegistry(r EncoderRegistry) Option {
return optionFunc(func(v *Viper) {
if r == nil {
return
}
v.encoderRegistry = r
})
}
@ -65,6 +69,10 @@ func WithEncoderRegistry(r EncoderRegistry) Option {
// WithDecoderRegistry sets a custom [DecoderRegistry].
func WithDecoderRegistry(r DecoderRegistry) Option {
return optionFunc(func(v *Viper) {
if r == nil {
return
}
v.decoderRegistry = r
})
}
@ -72,6 +80,10 @@ func WithDecoderRegistry(r DecoderRegistry) Option {
// WithCodecRegistry sets a custom [EncoderRegistry] and [DecoderRegistry].
func WithCodecRegistry(r CodecRegistry) Option {
return optionFunc(func(v *Viper) {
if r == nil {
return
}
v.encoderRegistry = r
v.decoderRegistry = r
})

View file

@ -9,6 +9,10 @@ import (
// WithFinder sets a custom [Finder].
func WithFinder(f Finder) Option {
return optionFunc(func(v *Viper) {
if f == nil {
return
}
v.finder = f
})
}
@ -34,6 +38,10 @@ func (c *combinedFinder) Find(fsys afero.Fs) ([]string, error) {
var errs []error
for _, finder := range c.finders {
if finder == nil {
continue
}
r, err := finder.Find(fsys)
if err != nil {
errs = append(errs, err)

View file

@ -247,6 +247,10 @@ type StringReplacer interface {
// EnvKeyReplacer sets a replacer used for mapping environment variables to internal keys.
func EnvKeyReplacer(r StringReplacer) Option {
return optionFunc(func(v *Viper) {
if r == nil {
return
}
v.envKeyReplacer = r
})
}