57 lines
975 B
Go
57 lines
975 B
Go
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
|
|
noCheckStatus bool
|
|
}
|
|
|
|
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
|
|
}
|
|
}
|
|
}
|
|
|
|
func WithNoCheckStatus(v bool) ConfigOpt {
|
|
return func(c *Config) {
|
|
c.noCheckStatus = v
|
|
}
|
|
}
|