models

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2024 License: MIT Imports: 7 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

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 (*Response) Bytes

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

func (*Response) Content

func (r *Response) Content() *ContentWrapper

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

func (*Response) GetURL

func (r *Response) GetURL() string

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