-
Notifications
You must be signed in to change notification settings - Fork 0
/
request.go
43 lines (34 loc) · 1.07 KB
/
request.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package httpclient
import (
"context"
"time"
"github.com/valyala/fasthttp"
)
// Do performs the given http request and fills the given http response.
func (c *Client) Do(req *fasthttp.Request, resp *fasthttp.Response) error {
if c.latencyFunc != nil {
defer c.latencyFunc(time.Now(), c.domain)
}
return c.HTTP.Do(req, resp)
}
// DoTimeout performs the given request and waits for response during
// the given timeout duration.
func (c *Client) DoTimeout(req *fasthttp.Request, resp *fasthttp.Response) error {
if c.latencyFunc != nil {
defer c.latencyFunc(time.Now(), c.domain)
}
return c.HTTP.DoTimeout(req, resp, c.Timeout)
}
// DoContext perform the given request with ctx deadline or waits for response during
// the given timeout duration.
func (c *Client) DoContext(ctx context.Context, req *fasthttp.Request, resp *fasthttp.Response) error {
if c.latencyFunc != nil {
defer c.latencyFunc(time.Now(), c.domain)
}
deadline, ok := ctx.Deadline()
if ok {
return c.HTTP.DoDeadline(req, resp, deadline)
} else {
return c.HTTP.DoTimeout(req, resp, c.Timeout)
}
}