MCPcopy Index your code
hub / github.com/coder/coder / newResponse

Function newResponse

codersdk/client_internal_test.go:358–381  ·  view source on GitHub ↗
(status int, contentType string, body interface{})

Source from the content-addressed store, hash-verified

356}
357
358func 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
383func marshal(res any) string {
384 b, err := json.Marshal(res)

Callers 2

Test_readBodyAsErrorFunction · 0.85
TestReadErrorBodyForLogFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected