mhttp

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Fetch

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

Fetch 请求封装

func NewFetch

func NewFetch(opts FetchOptions) *Fetch

NewFetch 创建一个 Fetch 实例

func (*Fetch) Do

func (f *Fetch) Do() ([]byte, error)

Get 发起 GET 请求,并返回响应 body Do 发起请求,使用 FetchOptions.Method,要求 Method 非空并且为标准 HTTP 方法 调用示例:

res, err := NewFetch(FetchOptions{URL: "https://...", Method: http.MethodPost, DataMap: m}).Do()

type FetchOptions

type FetchOptions struct {
	URL        string
	Data       []byte
	DataMap    map[string]any
	Params     map[string]string
	Headers    map[string]string
	Timeout    int    // seconds
	Retry      int    // 重试次数
	RetryDelay int    // 重试次数延迟 seconds
	Method     string // 允许值:GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS(不区分大小写,会在 Do 中规范化为大写)
	// MaxBodySize 限制读取响应体的最大字节数,0 表示不限制
	MaxBodySize int64
	// Proxy 可选:为本次请求使用的代理地址,例如 "http://127.0.0.1:7890"
	Proxy string
}

FetchOptions 请求选项

Jump to

Keyboard shortcuts

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