|
|
@@ -3,7 +3,7 @@ package http
|
|
|
import (
|
|
|
"bytes"
|
|
|
json2 "encoding/json"
|
|
|
- "io/ioutil"
|
|
|
+ "io"
|
|
|
"net/http"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
@@ -22,7 +22,7 @@ import (
|
|
|
_ "github.com/go-kratos/kratos/v2/encoding/proto"
|
|
|
)
|
|
|
|
|
|
-//DecodeRequest decodeRequest decodes the request body to object.
|
|
|
+// DecodeRequest decodeRequest decodes the request body to object.
|
|
|
func DecodeRequest(req *http.Request, v interface{}) error {
|
|
|
method := strings.ToUpper(req.Method)
|
|
|
if method == "POST" || method == "PUT" || method == "DELETE" {
|
|
|
@@ -35,7 +35,7 @@ func DecodeRequest(req *http.Request, v interface{}) error {
|
|
|
}
|
|
|
subtype := contentSubtype(contextType)
|
|
|
if codec := encoding.GetCodec(subtype); codec != nil {
|
|
|
- data, err := ioutil.ReadAll(req.Body)
|
|
|
+ data, err := io.ReadAll(req.Body)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
@@ -82,7 +82,7 @@ func parseForm(req *http.Request, v interface{}) error {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
-//EncodeResponse encodes the object to the HTTP response.
|
|
|
+// EncodeResponse encodes the object to the HTTP response.
|
|
|
func EncodeResponse(w http.ResponseWriter, r *http.Request, v interface{}) error {
|
|
|
codec := codecForRequest(r)
|
|
|
data, err := codec.Marshal(v)
|
|
|
@@ -195,6 +195,6 @@ func contentSubtype(contentType string) string {
|
|
|
}
|
|
|
|
|
|
func GetBody(r *http.Request) []byte {
|
|
|
- b, _ := ioutil.ReadAll(r.Body)
|
|
|
+ b, _ := io.ReadAll(r.Body)
|
|
|
return b
|
|
|
}
|