(status int, contentType string, body interface{})
| 356 | } |
| 357 | |
| 358 | func newResponse(status int, contentType string, body interface{}) *http.Response { |
| 359 | var r io.ReadCloser |
| 360 | switch v := body.(type) { |
| 361 | case string: |
| 362 | r = io.NopCloser(strings.NewReader(v)) |
| 363 | case []byte: |
| 364 | r = io.NopCloser(bytes.NewReader(v)) |
| 365 | case io.ReadCloser: |
| 366 | r = v |
| 367 | case io.Reader: |
| 368 | r = io.NopCloser(v) |
| 369 | default: |
| 370 | panic(fmt.Sprintf("unknown body type: %T", body)) |
| 371 | } |
| 372 | |
| 373 | return &http.Response{ |
| 374 | Status: http.StatusText(status), |
| 375 | StatusCode: status, |
| 376 | Header: http.Header{ |
| 377 | "Content-Type": []string{contentType}, |
| 378 | }, |
| 379 | Body: r, |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | func marshal(res any) string { |
| 384 | b, err := json.Marshal(res) |
no outgoing calls
no test coverage detected