mirror of
https://github.com/spf13/viper
synced 2024-11-04 20:27:02 +00:00
fix: do not allow setting dependencies to nil values
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
This commit is contained in:
parent
35a46059e3
commit
7dbe493dd1
3 changed files with 24 additions and 0 deletions
12
encoding.go
12
encoding.go
|
@ -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
|
||||
})
|
||||
|
|
|
@ -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)
|
||||
|
|
4
viper.go
4
viper.go
|
@ -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
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue