1
0
mirror of https://github.com/ggicci/httpin.git synced 2025-07-07 00:45:38 +02:00
Files
httpin/decoders.go

27 lines
557 B
Go
Raw Normal View History

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