Skip to content

Commit c2ab99b

Browse files
committed
docs(encoding): add docs to codec registry
Signed-off-by: Mark Sagi-Kazar <[email protected]>
1 parent 6429344 commit c2ab99b

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

encoding.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,22 @@ type CodecRegistry interface {
6161
// WithEncoderRegistry sets a custom [EncoderRegistry].
6262
func WithEncoderRegistry(r EncoderRegistry) Option {
6363
return optionFunc(func(v *Viper) {
64-
v.encoderRegistry2 = r
64+
v.encoderRegistry = r
6565
})
6666
}
6767

6868
// WithDecoderRegistry sets a custom [DecoderRegistry].
6969
func WithDecoderRegistry(r DecoderRegistry) Option {
7070
return optionFunc(func(v *Viper) {
71-
v.decoderRegistry2 = r
71+
v.decoderRegistry = r
7272
})
7373
}
7474

7575
// WithCodecRegistry sets a custom [EncoderRegistry] and [DecoderRegistry].
7676
func WithCodecRegistry(r CodecRegistry) Option {
7777
return optionFunc(func(v *Viper) {
78-
v.encoderRegistry2 = r
79-
v.decoderRegistry2 = r
78+
v.encoderRegistry = r
79+
v.decoderRegistry = r
8080
})
8181
}
8282

@@ -134,7 +134,7 @@ func (r codecRegistry) codec(format string) (Codec, bool) {
134134
return nil, false
135135
}
136136

137-
// DefaultCodecRegistry
137+
// DefaultCodecRegistry is a simple implementation of [CodecRegistry] that allows registering custom [Codec]s.
138138
type DefaultCodecRegistry struct {
139139
codecs map[string]Codec
140140

@@ -158,6 +158,8 @@ func (r *DefaultCodecRegistry) init() {
158158
}
159159

160160
// RegisterCodec registers a custom [Codec].
161+
//
162+
// Format is case-insensitive.
161163
func (r *DefaultCodecRegistry) RegisterCodec(format string, codec Codec) error {
162164
r.init()
163165

@@ -169,6 +171,9 @@ func (r *DefaultCodecRegistry) RegisterCodec(format string, codec Codec) error {
169171
return nil
170172
}
171173

174+
// Encoder implements the [EncoderRegistry] interface.
175+
//
176+
// Format is case-insensitive.
172177
func (r *DefaultCodecRegistry) Encoder(format string) (Encoder, error) {
173178
encoder, ok := r.codec(format)
174179
if !ok {
@@ -178,6 +183,9 @@ func (r *DefaultCodecRegistry) Encoder(format string) (Encoder, error) {
178183
return encoder, nil
179184
}
180185

186+
// Decoder implements the [DecoderRegistry] interface.
187+
//
188+
// Format is case-insensitive.
181189
func (r *DefaultCodecRegistry) Decoder(format string) (Decoder, error) {
182190
decoder, ok := r.codec(format)
183191
if !ok {

0 commit comments

Comments
 (0)