dcsunny před 2 roky
rodič
revize
fd584ea4be
1 změnil soubory, kde provedl 9 přidání a 0 odebrání
  1. 9 0
      http/handle.go

+ 9 - 0
http/handle.go

@@ -24,6 +24,9 @@ import (
 
 // DecodeRequest  decodeRequest decodes the request body to object.
 func DecodeRequest(req *http.Request, v interface{}) error {
+	if v == nil {
+		return nil
+	}
 	method := strings.ToUpper(req.Method)
 	if method == "POST" || method == "PUT" || method == "DELETE" {
 		contextType := req.Header.Get(ContentTypeHeader)
@@ -84,6 +87,9 @@ func parseForm(req *http.Request, v interface{}) error {
 
 // EncodeResponse encodes the object to the HTTP response.
 func EncodeResponse(w http.ResponseWriter, r *http.Request, v interface{}) error {
+	if v == nil {
+		return nil
+	}
 	codec := codecForRequest(r)
 	data, err := codec.Marshal(v)
 	if err != nil {
@@ -95,6 +101,9 @@ func EncodeResponse(w http.ResponseWriter, r *http.Request, v interface{}) error
 }
 
 func ErrHandle(w http.ResponseWriter, r *http.Request, err error) {
+	if err == nil {
+		return
+	}
 	st := errors.FromError(err)
 	if st == nil {
 		st = codes.Error(10500, err.Error()).(*errors.Error)