Documentation
¶
Index ¶
- Constants
- func BasicAuth(username, password string) xopt.Option[Request]
- func BodyJSON[T any](body T) xopt.Option[Request]
- func BodyMultipartForm(form *multipart.Form) xopt.Option[Request]
- func BodyText(body string) xopt.Option[Request]
- func BodyWWWFormURLEncoded(body url.Values) xopt.Option[Request]
- func BodyXML[T any](body T) xopt.Option[Request]
- func BodyYAML[T any](body T) xopt.Option[Request]
- func CheckRedirect(f func(req *http.Request, via []*http.Request) error) xopt.Option[Request]
- func Client(client *http.Client) xopt.Option[Request]
- func DecoderJSON() xopt.Option[Request]
- func DecoderText() xopt.Option[Request]
- func DecoderXML() xopt.Option[Request]
- func DecoderYAML() xopt.Option[Request]
- func Header(key, value string, replace ...bool) xopt.Option[Request]
- func Headers(headers http.Header, replace ...bool) xopt.Option[Request]
- func Jar(jar http.CookieJar) xopt.Option[Request]
- func Method(method string) xopt.Option[Request]
- func NativeBody(contentType string, body io.Reader) xopt.Option[Request]
- func RegisterInterceptors(i ...Interceptor)
- func Timeout(timeout time.Duration) xopt.Option[Request]
- func Transport(transport http.RoundTripper) xopt.Option[Request]
- func URLRawQuery(query url.Values) xopt.Option[Request]
- type Interceptor
- type InterceptorFunc
- type Request
- type Response
- type TraceResult
Constants ¶
View Source
const ( ContentType = "Content-Type" ContentTypeHTML = "text/html" ContentTypeJSON = "application/json" ContentTypeXML = "application/xml" ContentTypeYAML = "application/x-yaml" ContentTypeText = "text/plain" ContentTypeURLEncoded = "application/x-www-form-urlencoded" )
Variables ¶
This section is empty.
Functions ¶
func CheckRedirect ¶
func DecoderJSON ¶
func DecoderText ¶
func DecoderXML ¶
func DecoderYAML ¶
Types ¶
type Interceptor ¶
type Interceptor interface {
// 在请求发送前处理
Before(req *http.Request) error
// 在响应返回后处理
After(resp *http.Response, req *http.Request) error
}
Interceptor 定义拦截器接口
type InterceptorFunc ¶
type InterceptorFunc struct {
BeforeFunc func(req *http.Request) error
AfterFunc func(resp *http.Response, req *http.Request) error
}
InterceptorFunc 适配函数式拦截器
type Response ¶
type Response[T any] struct { Body T `json:"body" xml:"body" yaml:"body"` Code int `json:"code" xml:"code" yaml:"code"` *Request `json:"-" xml:"-" yaml:"-"` *TraceResult `json:"trace_result" xml:"trace_result" yaml:"trace_result"` }
func (*Response[T]) PrettyString ¶
type TraceResult ¶
type TraceResult struct {
TotalDuration Counter[time.Duration] `json:"total_duration"`
DNSDuration Counter[time.Duration] `json:"dns_duration"`
ConnectDuration Counter[time.Duration] `json:"connect_duration"`
TlsDuration Counter[time.Duration] `json:"tls_duration"`
FirstByteDelay Counter[time.Duration] `json:"first_byte_delay"`
// contains filtered or unexported fields
}
TraceResult 存储追踪结果
func (*TraceResult) FormatCounter ¶
func (tr *TraceResult) FormatCounter()
Click to show internal directories.
Click to hide internal directories.