add aditional check for nil message passed
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
		
							
								
								
									
										16
									
								
								http.go
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								http.go
									
									
									
									
									
								
							| @@ -41,6 +41,7 @@ func newRequest(addr string, req client.Request, ct string, cf codec.Codec, msg | ||||
| 	body := "*" // as like google api http annotation | ||||
|  | ||||
| 	var tags []string | ||||
| 	var scheme string | ||||
| 	u, err := url.Parse(addr) | ||||
| 	if err != nil { | ||||
| 		hreq.URL = &url.URL{ | ||||
| @@ -49,6 +50,7 @@ func newRequest(addr string, req client.Request, ct string, cf codec.Codec, msg | ||||
| 			Path:   req.Endpoint(), | ||||
| 		} | ||||
| 		hreq.Host = addr | ||||
| 		scheme = "http" | ||||
| 	} else { | ||||
| 		ep := req.Endpoint() | ||||
| 		if opts.Context != nil { | ||||
| @@ -86,24 +88,26 @@ func newRequest(addr string, req client.Request, ct string, cf codec.Codec, msg | ||||
| 		return nil, errors.BadRequest("go.micro.client", err.Error()) | ||||
| 	} | ||||
|  | ||||
| 	hreq.URL, err = url.Parse(addr + path) | ||||
| 	if scheme != "" { | ||||
| 		hreq.URL, err = url.Parse(scheme + "://" + addr + path) | ||||
| 	} else { | ||||
| 		hreq.URL, err = url.Parse(addr + path) | ||||
| 	} | ||||
| 	if err != nil { | ||||
| 		return nil, errors.BadRequest("go.micro.client", err.Error()) | ||||
| 	} | ||||
|  | ||||
| 	var b []byte | ||||
|  | ||||
| 	// marshal request is struct not empty | ||||
| 	if nmsg != nil { | ||||
| 		var b []byte | ||||
| 		b, err = cf.Marshal(nmsg) | ||||
| 		if err != nil { | ||||
| 			return nil, errors.BadRequest("go.micro.client", err.Error()) | ||||
| 		} | ||||
| 		hreq.Body = ioutil.NopCloser(bytes.NewBuffer(b)) | ||||
| 		hreq.ContentLength = int64(len(b)) | ||||
| 	} | ||||
|  | ||||
| 	hreq.Body = ioutil.NopCloser(bytes.NewBuffer(b)) | ||||
| 	hreq.ContentLength = int64(len(b)) | ||||
|  | ||||
| 	return hreq, nil | ||||
| } | ||||
|  | ||||
|   | ||||
							
								
								
									
										6
									
								
								util.go
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								util.go
									
									
									
									
									
								
							| @@ -28,6 +28,10 @@ func newPathRequest(path string, method string, body string, msg interface{}, ta | ||||
| 		return "", nil, err | ||||
| 	} | ||||
|  | ||||
| 	if len(tpl.Fields) > 0 && msg == nil { | ||||
| 		return "", nil, fmt.Errorf("nil message but path params requested: %v", path) | ||||
| 	} | ||||
|  | ||||
| 	fieldsmap := make(map[string]string, len(tpl.Fields)) | ||||
| 	for _, v := range tpl.Fields { | ||||
| 		fieldsmap[v] = "" | ||||
| @@ -95,7 +99,7 @@ func newPathRequest(path string, method string, body string, msg interface{}, ta | ||||
| 	// check not filled stuff | ||||
| 	for k, v := range fieldsmap { | ||||
| 		if v == "" { | ||||
| 			return "", nil, fmt.Errorf("path param %s not filled %s", k, v) | ||||
| 			return "", nil, fmt.Errorf("path param %s not filled", k) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user