Skip to content

Commit

Permalink
refactor(encoding): drop old codec registry
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Sagi-Kazar <[email protected]>
  • Loading branch information
sagikazarmark committed Jun 24, 2024
1 parent 7f90845 commit 687cfb7
Showing 1 changed file with 0 additions and 40 deletions.
40 changes: 0 additions & 40 deletions encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 687cfb7

Please sign in to comment.