35 lines
1.5 KiB
Go

package client
// HTTPClient defines the interface for sending HTTP requests.
// It supports both standard non-streaming and streaming (SSE) requests.
type HTTPClient interface {
// Do sends a standard non-streaming HTTP request.
Do(req *Request) (*Response, error)
// Stream sends an HTTP request and processes the response as a stream of Server-Sent Events (SSE).
// It calls the callback function for each received SSE chunk.
Stream(req *Request, callback func(chunk SSEChunk) error) error
}
// Request represents an HTTP request to be sent.
type Request struct {
Method string // HTTP method (e.g., "POST", "GET")
URL string // Request URL
Body []byte // Request body
Headers map[string]string // Request headers
IsStream bool // Indicates if this request expects a streaming response
}
// Response represents an HTTP response received from the server.
type Response struct {
StatusCode int // HTTP status code (e.g., 200, 404)
Body []byte // Response body (for non-streaming requests)
Headers map[string]string // Response headers
}
// SSEChunk represents a single chunk of data received in an SSE stream.
type SSEChunk struct {
Data []byte // Raw data content of the SSE event (typically JSON)
Timestamp int64 // Timestamp when the chunk was received (UnixNano)
IsDone bool // Flag indicating if this chunk represents the end of the stream (e.g., "data: [DONE]")
}