update
This commit is contained in:
49
myhttp/httpc/option.go
Normal file
49
myhttp/httpc/option.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package httpc
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
type (
|
||||
Config struct {
|
||||
timeout time.Duration
|
||||
client *http.Client
|
||||
transport *http.Transport
|
||||
redirectFn func(req *http.Request, via []*http.Request) error
|
||||
}
|
||||
|
||||
ConfigOpt func(c *Config)
|
||||
)
|
||||
|
||||
func WithTimout(v time.Duration) ConfigOpt {
|
||||
return func(c *Config) {
|
||||
c.timeout = v
|
||||
}
|
||||
}
|
||||
|
||||
func WithClient(v *http.Client) ConfigOpt {
|
||||
return func(c *Config) {
|
||||
c.client = v
|
||||
}
|
||||
}
|
||||
|
||||
func WithTransport(v *http.Transport) ConfigOpt {
|
||||
return func(c *Config) {
|
||||
c.transport = v
|
||||
}
|
||||
}
|
||||
|
||||
func WithRedirectFn(v func(req *http.Request, via []*http.Request) error) ConfigOpt {
|
||||
return func(c *Config) {
|
||||
c.redirectFn = v
|
||||
}
|
||||
}
|
||||
|
||||
func WithNoRedirect() ConfigOpt {
|
||||
return func(c *Config) {
|
||||
c.redirectFn = func(req *http.Request, via []*http.Request) error {
|
||||
return http.ErrUseLastResponse
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user