Documentation
¶
Index ¶
- type AuthType
- type BaseClient
- func (c *BaseClient) Do(ctx context.Context, req *Request) (*Response, error)
- func (c *BaseClient) DoJSON(ctx context.Context, req *Request, result interface{}) error
- func (c *BaseClient) GetMetrics() *metrics.Metrics
- func (c *BaseClient) StreamResponse(ctx context.Context, req *Request, handler SSEHandler) error
- func (c *BaseClient) UploadFile(ctx context.Context, path string, fieldName string, filename string, ...) (*Response, error)
- func (c *BaseClient) WithToken(token string) *BaseClient
- func (c *BaseClient) WithWorkspaceID(workspaceID string) *BaseClient
- type ClientConfig
- type JSONSSEHandler
- type Request
- type Response
- type SSEEvent
- type SSEHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseClient ¶
type BaseClient struct {
// contains filtered or unexported fields
}
BaseClient 基础HTTP客户端
func NewClientFromConfig ¶
func NewClientFromConfig(configPath string) (*BaseClient, error)
NewClientFromConfig 从配置创建客户端
func (*BaseClient) DoJSON ¶
func (c *BaseClient) DoJSON(ctx context.Context, req *Request, result interface{}) error
DoJSON 执行JSON请求并解析响应
func (*BaseClient) GetMetrics ¶
func (c *BaseClient) GetMetrics() *metrics.Metrics
GetMetrics 获取监控指标
func (*BaseClient) StreamResponse ¶
func (c *BaseClient) StreamResponse(ctx context.Context, req *Request, handler SSEHandler) error
StreamResponse 流式响应处理
func (*BaseClient) UploadFile ¶
func (c *BaseClient) UploadFile(ctx context.Context, path string, fieldName string, filename string, fileData []byte, extraFields map[string]string) (*Response, error)
UploadFile 上传文件
func (*BaseClient) WithToken ¶
func (c *BaseClient) WithToken(token string) *BaseClient
WithToken 设置认证token
func (*BaseClient) WithWorkspaceID ¶
func (c *BaseClient) WithWorkspaceID(workspaceID string) *BaseClient
WithWorkspaceID 设置工作空间ID
type ClientConfig ¶
type ClientConfig struct {
BaseURL string
AuthType AuthType
Token string
HTTPClient *http.Client
Timeout time.Duration
MaxRetries int
WorkspaceID *string
// 日志配置
Logger logger.Logger
// 监控配置
Metrics *metrics.Metrics
// 连接池配置
MaxIdleConns int
MaxIdleConnsPerHost int
IdleConnTimeout time.Duration
}
ClientConfig 客户端配置
type JSONSSEHandler ¶
type JSONSSEHandler struct {
OnEventFunc func(eventType string, data map[string]interface{}) error
OnErrorFunc func(err error)
OnCompleteFunc func()
}
JSONSSEHandler 将SSE事件解析为JSON的处理器
func (*JSONSSEHandler) OnEvent ¶
func (h *JSONSSEHandler) OnEvent(event *SSEEvent) error
OnEvent 处理SSE事件
type Request ¶
type Request struct {
Method string
Path string
Headers map[string]string
Query map[string]string
Body interface{}
}
Request 请求参数
type SSEHandler ¶
SSEHandler SSE事件处理器
Click to show internal directories.
Click to hide internal directories.