2021-04-30 13:10:07 +02:00
|
|
|
package httpin
|
|
|
|
|
2021-05-03 16:19:54 +02:00
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
|
2021-05-08 09:27:37 +02:00
|
|
|
"github.com/ggicci/httpin/internal"
|
|
|
|
)
|
2021-05-03 16:19:54 +02:00
|
|
|
|
2021-05-08 16:46:16 +02:00
|
|
|
// Decoder is the interface implemented by types that can decode bytes to
|
|
|
|
// themselves.
|
2021-05-08 09:27:37 +02:00
|
|
|
type Decoder internal.Decoder
|
2021-05-03 16:19:54 +02:00
|
|
|
|
2021-05-08 16:46:16 +02:00
|
|
|
// DecoderFunc is an adaptor to allow the use of ordinary functions as httpin
|
|
|
|
// decoders.
|
|
|
|
type DecoderFunc internal.DecoderFunc
|
|
|
|
|
2021-05-08 09:27:37 +02:00
|
|
|
var decoders = map[reflect.Type]Decoder{} // custom decoders
|
2021-05-03 16:19:54 +02:00
|
|
|
|
2021-05-08 16:46:16 +02:00
|
|
|
// decoderOf retrieves a decoder by type.
|
2021-05-03 16:19:54 +02:00
|
|
|
func decoderOf(t reflect.Type) Decoder {
|
2021-05-08 09:27:37 +02:00
|
|
|
dec := decoders[t]
|
2021-05-03 16:19:54 +02:00
|
|
|
if dec != nil {
|
|
|
|
return dec
|
|
|
|
}
|
2021-05-08 09:27:37 +02:00
|
|
|
return internal.DecoderOf(t)
|
2021-05-03 16:19:54 +02:00
|
|
|
}
|