-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplugin.go
More file actions
31 lines (26 loc) · 869 Bytes
/
plugin.go
File metadata and controls
31 lines (26 loc) · 869 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 logger
import (
"io"
"net/http"
"github.com/izumin5210/httplogger"
"gopkg.in/h2non/gentleman.v2/context"
"gopkg.in/h2non/gentleman.v2/plugin"
)
// New creates logger plugin instance
func New(out io.Writer) plugin.Plugin {
return new(func(parent http.RoundTripper) http.RoundTripper {
return httplogger.NewRoundTripper(out, parent)
})
}
// FromLogger creates logger plugin instance with a specified logger implementation
func FromLogger(writer httplogger.SimpleLogWriter) plugin.Plugin {
return new(func(parent http.RoundTripper) http.RoundTripper {
return httplogger.FromSimpleLogger(writer, parent)
})
}
func new(transportFn func(parent http.RoundTripper) http.RoundTripper) plugin.Plugin {
return plugin.NewRequestPlugin(func(c *context.Context, h context.Handler) {
c.Client.Transport = transportFn(c.Client.Transport)
h.Next(c)
})
}