transport/http: rename CodecForRequest func (#960)

Co-authored-by: 徐曙辉 <xushuhui@himango.cn>
pull/961/head
Shuhui Xu 4 years ago committed by GitHub
parent cc0214d78b
commit ce04916181
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      transport/http/handle.go

@ -171,7 +171,7 @@ func defaultRequestDecoder(req *http.Request, v interface{}) error {
// defaultResponseEncoder encodes the object to the HTTP response.
func defaultResponseEncoder(w http.ResponseWriter, r *http.Request, v interface{}) error {
codec := codecForRequest(r)
codec := CodecForRequest(r)
data, err := codec.Marshal(v)
if err != nil {
return err
@ -188,7 +188,7 @@ func defaultResponseEncoder(w http.ResponseWriter, r *http.Request, v interface{
// defaultErrorEncoder encodes the error to the HTTP response.
func defaultErrorEncoder(w http.ResponseWriter, r *http.Request, se error) {
codec := codecForRequest(r)
codec := CodecForRequest(r)
body, err := codec.Marshal(se)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
@ -205,8 +205,8 @@ func defaultErrorEncoder(w http.ResponseWriter, r *http.Request, se error) {
w.Write(body)
}
// codecForRequest get encoding.Codec via http.Request
func codecForRequest(r *http.Request) encoding.Codec {
// CodecForRequest get encoding.Codec via http.Request
func CodecForRequest(r *http.Request) encoding.Codec {
var codec encoding.Codec
for _, accept := range r.Header["Accept"] {
if codec = encoding.GetCodec(httputil.ContentSubtype(accept)); codec != nil {

Loading…
Cancel
Save