-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathlog.go
More file actions
31 lines (26 loc) · 734 Bytes
/
log.go
File metadata and controls
31 lines (26 loc) · 734 Bytes
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
package xhttp
import (
"context"
"time"
)
type Log struct {
Context context.Context `json:"context"`
Duration time.Duration `json:"duration"`
Request *Request `json:"request"` // The Request.RetryAttempts field records the number of retry attempts
Response *Response `json:"response"` // If request error this field is equal to nil
Error error `json:"error"`
}
type DebugFunc func(l *Log)
func (t *Client) doDebug(ctx context.Context, opts *RequestOptions, duration time.Duration, req *Request, resp *Response, err error) {
if opts.DebugFunc == nil {
return
}
l := &Log{
Context: ctx,
Duration: duration,
Request: req,
Response: resp,
Error: err,
}
opts.DebugFunc(l)
}