-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.go
43 lines (36 loc) · 1.05 KB
/
log.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 jsonhttpc
import (
"context"
"net/http"
)
// RequestLogger is a callback with request before make round trip.
type RequestLogger interface {
LogRequest(context.Context, *http.Request)
}
// ResponseLogger is a callback with response after round trip succeeded.
type ResponseLogger interface {
LogResponse(context.Context, *http.Response)
}
// RequestResponseLogger provides RequestLogger and Response by one object.
// It is supposed to use with WithRequestResponseLogger.
type RequestResponseLogger interface {
RequestLogger
ResponseLogger
}
// WithRequestLogger overrides RequestLogger of the client.
func (c *Client) WithRequestLogger(l RequestLogger) *Client {
c.lReq = l
return c
}
// WithResponseLogger overrides ResponseLogger of the client.
func (c *Client) WithResponseLogger(l ResponseLogger) *Client {
c.lResp = l
return c
}
// WithRequestResponseLogger overrides RequestLogger and ResponseLogger with an
// object in same time.
func (c *Client) WithRequestResponseLogger(l RequestResponseLogger) *Client {
c.lReq = l
c.lResp = l
return c
}