models

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 8, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupportedEncoding = errors.New("unsupported encoding format")

ErrUnsupportedEncoding 表示不支持的编码格式

Functions

func JSON

func JSON[T any](r *Response) (T, error)

JSON 使用泛型解析 JSON

func XML

func XML[T any](r *Response) (T, error)

XML 使用泛型解析 XML

Types

type ContentWrapper

type ContentWrapper struct {
	// contains filtered or unexported fields
}

ContentWrapper 封装响应体的二进制数据,并提供链式解码功能

func (*ContentWrapper) Decode

func (c *ContentWrapper) Decode(encoding string) (string, error)

Decode 使用指定的编码格式对内容进行解码

type DecodeError added in v0.1.2

type DecodeError struct {
	ContentType string
	Err         error
}

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

func CreateMockResponse(statusCode int, body []byte, headers http.Header) *Response

CreateMockResponse creates a Response for testing purposes.

func NewResponse

func NewResponse(resp *http.Response, finalURL string) (*Response, error)

NewResponse 初始化 Response 对象并读取响应体

func NewResponseFast

func NewResponseFast(resp *http.Response, finalURL string, body []byte) *Response

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) Bytes

func (r *Response) Bytes() []byte

func (*Response) Content

func (r *Response) Content() *ContentWrapper

Content 返回支持链式解码的封装对象

func (*Response) ContentType added in v0.1.2

func (r *Response) ContentType() string

ContentType returns the Content-Type header value.

func (*Response) DecodeJSON

func (r *Response) DecodeJSON(dest any) error

func (*Response) DecodeXML

func (r *Response) DecodeXML(dest any) error

func (*Response) GetURL

func (r *Response) GetURL() string

func (*Response) IsClientError added in v0.1.2

func (r *Response) IsClientError() bool

IsClientError returns true if status code is 4xx.

func (*Response) IsError

func (r *Response) IsError() bool

IsError returns true if status code is 4xx or 5xx.

func (*Response) IsRedirect added in v0.1.2

func (r *Response) IsRedirect() bool

IsRedirect returns true if status code is 3xx.

func (*Response) IsServerError added in v0.1.2

func (r *Response) IsServerError() bool

IsServerError returns true if status code is 5xx.

func (*Response) IsSuccess

func (r *Response) IsSuccess() bool

IsSuccess returns true if status code is 2xx.

func (*Response) Raw

func (r *Response) Raw() *http.Response

Raw 返回原始 http.Response 对象

func (*Response) Text

func (r *Response) Text() string

Text 返回响应的文本形式(使用 UTF-8 解码)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL