MCPcopy Index your code
hub / github.com/DoNewsCode/core / Do

Method Do

clihttp/client.go:74–97  ·  view source on GitHub ↗

Do sends the request.

(req *http.Request)

Source from the content-addressed store, hash-verified

72
73// Do sends the request.
74func (c *Client) Do(req *http.Request) (*http.Response, error) {
75 clientSpan, ctx := opentracing.StartSpanFromContextWithTracer(req.Context(), c.tracer, "HTTP Client")
76 defer clientSpan.Finish()
77
78 req = req.WithContext(ctx)
79
80 ext.SpanKindRPCClient.Set(clientSpan)
81 ext.HTTPUrl.Set(clientSpan, req.RequestURI)
82 ext.HTTPMethod.Set(clientSpan, req.Method)
83
84 // Inject the client span context into the headers
85 c.logRequest(req, clientSpan)
86
87 c.tracer.Inject(clientSpan.Context(), opentracing.HTTPHeaders, opentracing.HTTPHeadersCarrier(req.Header))
88 response, err := c.underlying.Do(req)
89 if err != nil {
90 ext.LogError(clientSpan, err)
91 return response, err
92 }
93
94 c.logResponse(response, clientSpan)
95
96 return response, err
97}
98
99func (c *Client) logRequest(req *http.Request, span opentracing.Span) {
100 if req.Body == nil || c.requestLogThreshold <= 0 {

Callers 5

TestClient_DoFunction · 0.95
TestClient_OptionFunction · 0.95
TestClient_raceFunction · 0.95
TestClient_contextFunction · 0.95
ExampleFunction · 0.95

Calls 5

logRequestMethod · 0.95
logResponseMethod · 0.95
InjectMethod · 0.80
DoMethod · 0.65
SetMethod · 0.45

Tested by 5

TestClient_DoFunction · 0.76
TestClient_OptionFunction · 0.76
TestClient_raceFunction · 0.76
TestClient_contextFunction · 0.76
ExampleFunction · 0.76