Просмотр исходного кода

move ioutil.ReadAll() call into if stmt scope

Kale Blankenship 8 лет назад
Родитель
Сommit
f3e6640e1c
2 измененных файлов: 2 добавлений и 4 удалений
  1. 1
    2
      internal/driver/fetch.go
  2. 1
    2
      internal/symbolizer/symbolizer.go

+ 1
- 2
internal/driver/fetch.go Просмотреть файл

@@ -403,8 +403,7 @@ func fetchURL(source string, timeout time.Duration) (io.ReadCloser, error) {
403 403
 func statusCodeError(resp *http.Response) error {
404 404
 	if resp.Header.Get("X-Go-Pprof") != "" && strings.Contains(resp.Header.Get("Content-Type"), "text/plain") {
405 405
 		// error is from pprof endpoint
406
-		body, err := ioutil.ReadAll(resp.Body)
407
-		if err == nil {
406
+		if body, err := ioutil.ReadAll(resp.Body); err == nil {
408 407
 			return fmt.Errorf("server response: %s - %s", resp.Status, body)
409 408
 		}
410 409
 	}

+ 1
- 2
internal/symbolizer/symbolizer.go Просмотреть файл

@@ -104,8 +104,7 @@ func postURL(source, post string) ([]byte, error) {
104 104
 func statusCodeError(resp *http.Response) error {
105 105
 	if resp.Header.Get("X-Go-Pprof") != "" && strings.Contains(resp.Header.Get("Content-Type"), "text/plain") {
106 106
 		// error is from pprof endpoint
107
-		body, err := ioutil.ReadAll(resp.Body)
108
-		if err == nil {
107
+		if body, err := ioutil.ReadAll(resp.Body); err == nil {
109 108
 			return fmt.Errorf("server response: %s - %s", resp.Status, body)
110 109
 		}
111 110
 	}