mirror of
https://github.com/spf13/viper
synced 2024-12-22 03:27:03 +00:00
refactor(encoding): drop old codec registry
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
This commit is contained in:
parent
7f90845afc
commit
687cfb73cf
1 changed files with 0 additions and 40 deletions
40
encoding.go
40
encoding.go
|
@ -77,46 +77,6 @@ func WithCodecRegistry(r CodecRegistry) Option {
|
|||
})
|
||||
}
|
||||
|
||||
type codecRegistry struct {
|
||||
v *Viper
|
||||
}
|
||||
|
||||
func (r codecRegistry) Encoder(format string) (Encoder, error) {
|
||||
encoder, ok := r.codec(format)
|
||||
if !ok {
|
||||
return nil, errors.New("encoder not found for this format")
|
||||
}
|
||||
|
||||
return encoder, nil
|
||||
}
|
||||
|
||||
func (r codecRegistry) Decoder(format string) (Decoder, error) {
|
||||
decoder, ok := r.codec(format)
|
||||
if !ok {
|
||||
return nil, errors.New("decoder not found for this format")
|
||||
}
|
||||
|
||||
return decoder, nil
|
||||
}
|
||||
|
||||
func (r codecRegistry) codec(format string) (Codec, bool) {
|
||||
switch strings.ToLower(format) {
|
||||
case "yaml", "yml":
|
||||
return yaml.Codec{}, true
|
||||
|
||||
case "json":
|
||||
return json.Codec{}, true
|
||||
|
||||
case "toml":
|
||||
return toml.Codec{}, true
|
||||
|
||||
case "dotenv", "env":
|
||||
return &dotenv.Codec{}, true
|
||||
}
|
||||
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// DefaultCodecRegistry is a simple implementation of [CodecRegistry] that allows registering custom [Codec]s.
|
||||
type DefaultCodecRegistry struct {
|
||||
codecs map[string]Codec
|
||||
|
|
Loading…
Reference in a new issue