http_utils

package
v1.0.20 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 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 HTTPClient

type HTTPClient struct {
	Client *http.Client
}

func NewHTTPClient

func NewHTTPClient() *HTTPClient

func (*HTTPClient) ExecuteRequest added in v1.0.9

func (c *HTTPClient) ExecuteRequest(r *HTTPRequest) (*http.Response, error)

ExecuteRequest 发送HTTP请求并返回响应

func (*HTTPClient) GetResponseData added in v1.0.9

func (c *HTTPClient) GetResponseData(r *HTTPRequest) ([]byte, error)

GetResponseData 发送HTTP请求读取并返回响应数据

func (*HTTPClient) SaveResponseToFile added in v1.0.9

func (c *HTTPClient) SaveResponseToFile(r *HTTPRequest, filepath string) error

SaveResponseToFile 发送HTTP请求并将响应数据保存为文件

func (*HTTPClient) SetProxy added in v1.0.8

func (c *HTTPClient) SetProxy(proxyFunc func(req *http.Request) (*url.URL, error))

func (*HTTPClient) SetTimeout added in v1.0.8

func (c *HTTPClient) SetTimeout(timeout time.Duration)

type HTTPRequest

type HTTPRequest struct {
	Method string
	APIUrl string
	Query  map[string]string
	Header map[string]string
	Body   any
}

HTTPRequest 包含apiUrl和headers

func NewHTTPRequest

func NewHTTPRequest(method, apiUrl string, query, header map[string]string, body any) *HTTPRequest

type SSEMessage added in v1.0.18

type SSEMessage struct {
	Event   string // 事件类型(可选)
	Data    []byte // 消息内容(必填),支持多行文本(自动分割为多个 data: 行)
	ID      string // 消息ID(可选)
	Comment string // 注释(可选),以冒号开头
	Retry   int    // 客户端重连时间(单位:毫秒,可选)
}

SSEMessage SSE标准消息

func (*SSEMessage) Encode added in v1.0.18

func (sm *SSEMessage) Encode() string

Jump to

Keyboard shortcuts

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