MCPcopy
hub / github.com/spf13/viper / unmarshalReader

Method unmarshalReader

viper.go:1701–1732  ·  view source on GitHub ↗
(in io.Reader, c map[string]any)

Source from the content-addressed store, hash-verified

1699}
1700
1701func (v *Viper) unmarshalReader(in io.Reader, c map[string]any) error {
1702 format := strings.ToLower(v.getConfigType())
1703 if format == "" {
1704 return errors.New("cannot decode configuration: unable to determine config type")
1705 }
1706
1707 buf := new(bytes.Buffer)
1708 _, err := buf.ReadFrom(in)
1709 if err != nil {
1710 return fmt.Errorf("failed to read configuration from input: %w", err)
1711 }
1712
1713 // TODO: remove this once SupportedExts is deprecated/removed
1714 if !slices.Contains(SupportedExts, format) {
1715 return UnsupportedConfigError(format)
1716 }
1717
1718 // TODO: return [UnsupportedConfigError] if the registry does not contain the format
1719 // TODO: consider deprecating this error type
1720 decoder, err := v.decoderRegistry.Decoder(format)
1721 if err != nil {
1722 return ConfigParseError{err}
1723 }
1724
1725 err = decoder.Decode(buf.Bytes(), c)
1726 if err != nil {
1727 return ConfigParseError{err}
1728 }
1729
1730 insensitiviseMap(c)
1731 return nil
1732}
1733
1734// Marshal a map into Writer.
1735func (v *Viper) marshalWriter(w io.Writer, configType string) error {

Callers 14

ReadInConfigMethod · 0.95
ReadConfigMethod · 0.95
MergeConfigMethod · 0.95
getRemoteConfigMethod · 0.95
watchRemoteConfigMethod · 0.95
initConfigsFunction · 0.80
initConfigFunction · 0.80
TestUnmarshalingFunction · 0.80
TestRemotePrecedenceFunction · 0.80
TestSubWithKeyDelimiterFunction · 0.80
TestDotParameterFunction · 0.80

Calls 5

getConfigTypeMethod · 0.95
UnsupportedConfigErrorTypeAlias · 0.85
insensitiviseMapFunction · 0.85
DecoderMethod · 0.65
DecodeMethod · 0.65

Tested by 8

initConfigsFunction · 0.64
initConfigFunction · 0.64
TestUnmarshalingFunction · 0.64
TestRemotePrecedenceFunction · 0.64
TestSubWithKeyDelimiterFunction · 0.64
TestDotParameterFunction · 0.64
TestKeyDelimiterFunction · 0.64
TestSliceIndexAccessFunction · 0.64