models

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 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 Response

type Response struct {
	StatusCode int
	Headers    http.Header
	Cookies    []*http.Cookie

	Proto string // 协议版本 (HTTP/1.1 或 HTTP/2.0)
	// contains filtered or unexported fields
}

Response 表示 HTTP 响应

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

func (r *Response) IsError() bool

IsError returns true if status code is 4xx or 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