|
|
@ -37,6 +37,7 @@ func DefaultRequestQuery(r *http.Request, v any) error { |
|
|
|
return binding.BindQuery(r.URL.Query(), v) |
|
|
|
return binding.BindQuery(r.URL.Query(), v) |
|
|
|
} |
|
|
|
} |
|
|
|
func DefaultRequestDecoder(r *http.Request, v any) error { |
|
|
|
func DefaultRequestDecoder(r *http.Request, v any) error { |
|
|
|
|
|
|
|
fmt.Println("request decoder") |
|
|
|
codec, ok := CodeForRequest(r, "Content-type") |
|
|
|
codec, ok := CodeForRequest(r, "Content-type") |
|
|
|
if !ok { |
|
|
|
if !ok { |
|
|
|
return errors.BadRequest("CODEC", fmt.Sprintf("unregister Content-Type: %s", codec)) |
|
|
|
return errors.BadRequest("CODEC", fmt.Sprintf("unregister Content-Type: %s", codec)) |
|
|
@ -88,6 +89,7 @@ func DefaultErrorEncoder(w http.ResponseWriter, r *http.Request, err error) { |
|
|
|
func CodeForRequest(r *http.Request, name string) (encoding.Codec, bool) { |
|
|
|
func CodeForRequest(r *http.Request, name string) (encoding.Codec, bool) { |
|
|
|
for _, accept := range r.Header[name] { |
|
|
|
for _, accept := range r.Header[name] { |
|
|
|
a := httputil.ContentSubtype(accept) |
|
|
|
a := httputil.ContentSubtype(accept) |
|
|
|
|
|
|
|
fmt.Println("aaa", name, a) |
|
|
|
codec := encoding.GetCodec(a) |
|
|
|
codec := encoding.GetCodec(a) |
|
|
|
if codec != nil { |
|
|
|
if codec != nil { |
|
|
|
return codec, true |
|
|
|
return codec, true |
|
|
|