Documentation
¶
Index ¶
- Variables
- func JSON[T any](r *Response) (T, error)
- func XML[T any](r *Response) (T, error)
- type ContentWrapper
- type DecodeError
- type Response
- func (r *Response) Bytes() []byte
- func (r *Response) Content() *ContentWrapper
- func (r *Response) ContentType() string
- func (r *Response) DecodeJSON(dest any) error
- func (r *Response) DecodeXML(dest any) error
- func (r *Response) GetURL() string
- func (r *Response) IsClientError() bool
- func (r *Response) IsError() bool
- func (r *Response) IsRedirect() bool
- func (r *Response) IsServerError() bool
- func (r *Response) IsSuccess() bool
- func (r *Response) Raw() *http.Response
- func (r *Response) Text() string
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrUnsupportedEncoding = errors.New("unsupported encoding format")
ErrUnsupportedEncoding 表示不支持的编码格式
Functions ¶
Types ¶
type ContentWrapper ¶
type ContentWrapper struct {
// contains filtered or unexported fields
}
ContentWrapper 封装响应体的二进制数据,并提供链式解码功能
type DecodeError ¶ added in v0.1.2
DecodeError represents an error during response body decoding.
func (*DecodeError) Error ¶ added in v0.1.2
func (e *DecodeError) Error() string
func (*DecodeError) Unwrap ¶ added in v0.1.2
func (e *DecodeError) Unwrap() error
type Response ¶
type Response struct {
StatusCode int
Status string // HTTP status text (e.g., "200 OK")
Headers http.Header
Cookies []*http.Cookie
Proto string // 协议版本 (HTTP/1.1 或 HTTP/2.0)
// contains filtered or unexported fields
}
Response 表示 HTTP 响应
func CreateMockResponse ¶ added in v0.1.2
CreateMockResponse creates a Response for testing purposes.
func NewResponse ¶
NewResponse 初始化 Response 对象并读取响应体
func NewResponseFast ¶
NewResponseFast creates a Response without copying the body. Warning: The response body must not be modified after this call. Use this only when you know the body won't be modified.
func (*Response) ContentType ¶ added in v0.1.2
ContentType returns the Content-Type header value.
func (*Response) DecodeJSON ¶
func (*Response) IsClientError ¶ added in v0.1.2
IsClientError returns true if status code is 4xx.
func (*Response) IsRedirect ¶ added in v0.1.2
IsRedirect returns true if status code is 3xx.
func (*Response) IsServerError ¶ added in v0.1.2
IsServerError returns true if status code is 5xx.
Click to show internal directories.
Click to hide internal directories.