39 lines
944 B
Go
39 lines
944 B
Go
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
|
||
}
|