You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
866 B
53 lines
866 B
package http
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
type RequestOption func(*Request)
|
|
|
|
func WithHost(host string) RequestOption {
|
|
return func(p *Request) {
|
|
p.Host = host
|
|
}
|
|
}
|
|
|
|
func WithUrl(url string) RequestOption {
|
|
return func(p *Request) {
|
|
p.Url = url
|
|
}
|
|
}
|
|
|
|
func WithBodySize(bodySize int) RequestOption {
|
|
return func(p *Request) {
|
|
p.bodySize = bodySize
|
|
}
|
|
}
|
|
|
|
func WithMethod(method string) RequestOption {
|
|
return func(p *Request) {
|
|
p.Method = method
|
|
}
|
|
}
|
|
|
|
func WithTransport(transport *http.Transport) RequestOption {
|
|
return func(p *Request) {
|
|
p.Transport = transport
|
|
}
|
|
}
|
|
|
|
func WithTimeout(timeout time.Duration) RequestOption {
|
|
return func(p *Request) {
|
|
p.Timeout = timeout
|
|
}
|
|
}
|
|
|
|
func WithRequestType(requestType RequestType) RequestOption {
|
|
return func(p *Request) {
|
|
if _, ok := types[requestType]; ok {
|
|
p.requestType = requestType
|
|
}
|
|
}
|
|
}
|