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

Method RoundTrip

_examples/customization.go:50–72  ·  view source on GitHub ↗

RoundTrip executes a request and returns a response.

(req *http.Request)

Source from the content-addressed store, hash-verified

48
49// RoundTrip executes a request and returns a response.
50func (t *CountingTransport) RoundTrip(req *http.Request) (*http.Response, error) {
51 var b bytes.Buffer
52
53 atomic.AddUint64(&t.count, 1)
54
55 req.Header.Set("Accept", "application/yaml")
56 req.Header.Set("X-Request-ID", "foo-123")
57
58 res, err := http.DefaultTransport.RoundTrip(req)
59
60 b.WriteString(strings.Repeat("-", 80) + "\n")
61 fmt.Fprintf(&b, "%s %s", req.Method, req.URL.String())
62
63 if err == nil {
64 fmt.Fprintf(&b, " [%s] %s\n", res.Status, res.Header.Get("Content-Type"))
65 } else {
66 fmt.Fprintf(&b, "ERROR: %s\n", err)
67 }
68
69 b.WriteTo(os.Stdout)
70
71 return res, err
72}
73
74func main() {
75 var wg sync.WaitGroup

Callers

nothing calls this directly

Calls 4

WriteToMethod · 0.80
SetMethod · 0.45
StringMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected