mirror of
https://github.com/spf13/viper
synced 2024-12-22 03:27:03 +00:00
feat(encoding): make format case-insensitive
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
This commit is contained in:
parent
93bf64aaa3
commit
d2221e2ef9
1 changed files with 7 additions and 1 deletions
|
@ -36,6 +36,8 @@ type Codec interface {
|
|||
|
||||
// EncoderRegistry returns an [Encoder] for a given format.
|
||||
//
|
||||
// Format is case-insensitive.
|
||||
//
|
||||
// [EncoderRegistry] returns an error if no [Encoder] is registered for the format.
|
||||
type EncoderRegistry interface {
|
||||
Encoder(format string) (Encoder, error)
|
||||
|
@ -43,6 +45,8 @@ type EncoderRegistry interface {
|
|||
|
||||
// DecoderRegistry returns an [Decoder] for a given format.
|
||||
//
|
||||
// Format is case-insensitive.
|
||||
//
|
||||
// [DecoderRegistry] returns an error if no [Decoder] is registered for the format.
|
||||
type DecoderRegistry interface {
|
||||
Decoder(format string) (Decoder, error)
|
||||
|
@ -99,7 +103,7 @@ func (r codecRegistry) Decoder(format string) (Decoder, error) {
|
|||
}
|
||||
|
||||
func (r codecRegistry) codec(format string) (Codec, bool) {
|
||||
switch format {
|
||||
switch strings.ToLower(format) {
|
||||
case "yaml", "yml":
|
||||
return yaml.Codec{}, true
|
||||
|
||||
|
@ -187,6 +191,8 @@ func (r *DefaultCodecRegistry) codec(format string) (Codec, bool) {
|
|||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
|
||||
format = strings.ToLower(format)
|
||||
|
||||
if r.codecs != nil {
|
||||
codec, ok := r.codecs[format]
|
||||
if ok {
|
||||
|
|
Loading…
Reference in a new issue