http_utils

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSSEHandler added in v1.1.2

func NewSSEHandler(onClient func(client *SSEWriter)) http.HandlerFunc

NewSSEHandler 返回一个 HTTP Handler,用于升级连接为 SSE

Types

type HTTPClient

type HTTPClient struct {
	Client *http.Client
	Logger *log.Logger // 日志记录器
}

HTTPClient HTTP客户端封装

func NewHTTPClient

func NewHTTPClient() *HTTPClient

NewHTTPClient 创建新的HTTP客户端

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) SetInsecureSkipVerify added in v1.1.0

func (c *HTTPClient) SetInsecureSkipVerify(skip bool)

SetInsecureSkipVerify 设置跳过TLS证书验证

func (*HTTPClient) SetLogger added in v1.1.0

func (c *HTTPClient) SetLogger(logger *log.Logger)

SetLogger 设置自定义日志器

func (*HTTPClient) SetProxy added in v1.0.8

func (c *HTTPClient) SetProxy(proxyURL string) error

SetProxy 设置代理

func (*HTTPClient) SetTimeout added in v1.0.8

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

SetTimeout 设置超时时间

func (*HTTPClient) SetTransport added in v1.1.0

func (c *HTTPClient) SetTransport(transport *http.Transport)

SetTransport 设置自定义传输层

type HTTPRequest

type HTTPRequest struct {
	Method string
	Url    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 // 消息内容(必填),支持多行文本
	ID      string // 消息ID(可选)
	Comment string // 注释(可选),以冒号开头
	Retry   int    // 客户端重连时间(单位:毫秒,可选)
}

SSEMessage SSE标准消息

func (*SSEMessage) Encode added in v1.0.18

func (sm *SSEMessage) Encode() []byte

type SSEWriter added in v1.1.2

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

SSEWriter 表示一个 SSE 客户端连接

func (*SSEWriter) Close added in v1.1.2

func (c *SSEWriter) Close()

Close 手动关闭连接

func (*SSEWriter) Send added in v1.1.2

func (c *SSEWriter) Send(msg SSEMessage) error

Send 发送一条 SSE 消息

Jump to

Keyboard shortcuts

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