Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ContextKeyRequestStart = &contextKey{"RequestStart"}
View Source
var DefaultLogRequest = func(req *http.Request) string { header, _ := json.Marshal(req.Header) body := []byte("") if req.Body != nil { body, _ = ioutil.ReadAll(req.Body) req.Body = ioutil.NopCloser(bytes.NewBuffer(body)) } return fmt.Sprintf("\n--> \n%s %s\n%s\n%s", req.Method, req.URL, string(header), string(body)) }
Used if transport.LogRequest is not set.
View Source
var DefaultLogResponse = func(resp *http.Response) string { ctx := resp.Request.Context() header, _ := json.Marshal(resp.Header) body, _ := ioutil.ReadAll(resp.Body) resp.Body = ioutil.NopCloser(bytes.NewBuffer(body)) if start, ok := ctx.Value(ContextKeyRequestStart).(time.Time); ok { return fmt.Sprintf("\n<--\n %d (%s)\n%s\n%s", resp.StatusCode, time.Since(start), string(header), string(body)) } else { return fmt.Sprintf("\n<-- \n%d\n%s\n%s", resp.StatusCode, string(header), string(body)) } }
Used if transport.LogResponse is not set.
View Source
var DefaultTransport = &Transport{ Transport: http.DefaultTransport, }
THe default logging transport that wraps http.DefaultTransport.
Functions ¶
This section is empty.
Types ¶
type Transport ¶
type Transport struct { Transport http.RoundTripper LogRequest func(req *http.Request) string LogResponse func(resp *http.Response) string Logger *logrus.Logger }
Transport implements http.RoundTripper. When set as Transport of http.Client, it executes HTTP requests with logging. No field is mandatory.
Click to show internal directories.
Click to hide internal directories.