39 lines
944 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package httpclient
// Request 表示 HTTP 请求
// 包含方法、URL、Body 和 Header
// 可在后续实现中扩展 Field
type Request struct {
Method string
URL string
Body []byte
Headers map[string]string
}
// Response 表示 HTTP 响应
// 包含状态码、Body 和 Header
type Response struct {
StatusCode int
Body []byte
Headers map[string]string
}
// SSEChunk 表示 SSE 流中的一块数据
// Data 为 JSON 数据Timestamp 记录接收时间IsDone 标记 [DONE]
type SSEChunk struct {
Data []byte // JSON 数据
Timestamp int64 // 接收时间戳UnixNano
IsDone bool // 是否为 [DONE]
}
// HTTPClient 定义通用的 Do 和 Stream 方法接口
// 后续根据 client 类型实现 fasthttp 或 net/http
type HTTPClient interface {
Do(req *Request) (*Response, error)
Stream(req *Request, callback func(chunk SSEChunk) error) error
}