From 687cfb73cf1545255b9eae482a0c0591e85595dd Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Mon, 24 Jun 2024 15:11:51 +0200 Subject: [PATCH] refactor(encoding): drop old codec registry Signed-off-by: Mark Sagi-Kazar --- encoding.go | 40 ---------------------------------------- 1 file changed, 40 deletions(-) diff --git a/encoding.go b/encoding.go index 1d6cd60..52511db 100644 --- a/encoding.go +++ b/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