mirror of
https://github.com/spf13/viper
synced 2024-12-22 19:47:01 +00:00
feat: return error when no config type is set
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
This commit is contained in:
parent
afe3be23cb
commit
a42c1b9f76
1 changed files with 8 additions and 0 deletions
8
viper.go
8
viper.go
|
@ -1577,6 +1577,10 @@ func (v *Viper) MergeInConfig() error {
|
||||||
func ReadConfig(in io.Reader) error { return v.ReadConfig(in) }
|
func ReadConfig(in io.Reader) error { return v.ReadConfig(in) }
|
||||||
|
|
||||||
func (v *Viper) ReadConfig(in io.Reader) error {
|
func (v *Viper) ReadConfig(in io.Reader) error {
|
||||||
|
if v.configType == "" {
|
||||||
|
return errors.New("cannot decode configuration: config type is not set")
|
||||||
|
}
|
||||||
|
|
||||||
v.config = make(map[string]any)
|
v.config = make(map[string]any)
|
||||||
return v.unmarshalReader(in, v.config)
|
return v.unmarshalReader(in, v.config)
|
||||||
}
|
}
|
||||||
|
@ -1585,6 +1589,10 @@ func (v *Viper) ReadConfig(in io.Reader) error {
|
||||||
func MergeConfig(in io.Reader) error { return v.MergeConfig(in) }
|
func MergeConfig(in io.Reader) error { return v.MergeConfig(in) }
|
||||||
|
|
||||||
func (v *Viper) MergeConfig(in io.Reader) error {
|
func (v *Viper) MergeConfig(in io.Reader) error {
|
||||||
|
if v.configType == "" {
|
||||||
|
return errors.New("cannot decode configuration: config type is not set")
|
||||||
|
}
|
||||||
|
|
||||||
cfg := make(map[string]any)
|
cfg := make(map[string]any)
|
||||||
if err := v.unmarshalReader(in, cfg); err != nil {
|
if err := v.unmarshalReader(in, cfg); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in a new issue