MCPcopy
hub / github.com/elastic/go-elasticsearch / String

Method String

esapi/esapi.response.go:46–79  ·  view source on GitHub ↗

String returns the response as a string. The intended usage is for testing or debugging only.

()

Source from the content-addressed store, hash-verified

44//
45// The intended usage is for testing or debugging only.
46func (r *Response) String() string {
47 var (
48 out = new(bytes.Buffer)
49 b1 = bytes.NewBuffer([]byte{})
50 b2 = bytes.NewBuffer([]byte{})
51 tr io.Reader
52 )
53
54 if r != nil && r.Body != nil {
55 tr = io.TeeReader(r.Body, b1)
56 defer r.Body.Close()
57
58 if _, err := io.Copy(b2, tr); err != nil {
59 _, _ = fmt.Fprintf(out, "<error reading response body: %v>", err)
60 return out.String()
61 }
62 defer func() { r.Body = io.NopCloser(b1) }()
63 }
64
65 if r != nil {
66 _, _ = fmt.Fprintf(out, "[%d %s]", r.StatusCode, http.StatusText(r.StatusCode))
67 if r.StatusCode > 0 {
68 out.WriteRune(' ')
69 }
70 } else {
71 out.WriteString("[0 <nil>]")
72 }
73
74 if r != nil && r.Body != nil {
75 _, _ = out.ReadFrom(b2)
76 }
77
78 return out.String()
79}
80
81// Status returns the response status as a string.
82func (r *Response) Status() string {

Callers 15

TestBulkIndexerFunction · 0.45
TestJSONReaderFunction · 0.45
BenchmarkBulkIndexerFunction · 0.45
BenchmarkJSONReaderFunction · 0.45
flushBufferMethod · 0.45
DoMethod · 0.45
DoMethod · 0.45
DoMethod · 0.45
DoMethod · 0.45
DoMethod · 0.45
DoMethod · 0.45
DoMethod · 0.45

Calls 1

CloseMethod · 0.65

Tested by 8

TestBulkIndexerFunction · 0.36
TestJSONReaderFunction · 0.36
BenchmarkBulkIndexerFunction · 0.36
BenchmarkJSONReaderFunction · 0.36
ExampleResponse_StringFunction · 0.36
BenchmarkAPIFunction · 0.36
TestAPIRequestFunction · 0.36
TestAPIResponseFunction · 0.36