client

package
v0.1.36 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthType

type AuthType string

AuthType 认证类型

const (
	AuthTypeBearer AuthType = "Bearer"
	AuthTypeAPIKey AuthType = "ApiKey"
)

type BaseClient

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

BaseClient 基础HTTP客户端

func NewBaseClient

func NewBaseClient(config *ClientConfig) *BaseClient

NewBaseClient 创建基础客户端

func NewClientFromConfig

func NewClientFromConfig(configPath string) (*BaseClient, error)

NewClientFromConfig 从配置创建客户端

func (*BaseClient) Do

func (c *BaseClient) Do(ctx context.Context, req *Request) (*Response, error)

Do 执行HTTP请求

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) WithCookies added in v0.1.16

func (c *BaseClient) WithCookies(cookies map[string]string) *BaseClient

WithCookies 设置cookies

func (*BaseClient) WithLogger added in v0.1.4

func (c *BaseClient) WithLogger(logger *slog.Logger) *BaseClient

WithLogger 设置日志器

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
	SkipTLS    bool

	WorkspaceID *string
	Cookies     map[string]string

	// 监控配置
	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) OnComplete

func (h *JSONSSEHandler) OnComplete()

OnComplete 处理完成

func (*JSONSSEHandler) OnError

func (h *JSONSSEHandler) OnError(err error)

OnError 处理错误

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 Response

type Response struct {
	StatusCode int
	Headers    http.Header
	Body       []byte
	Cookies    map[string]string // Cookie 名称到值的映射
}

Response 响应

type SSEEvent

type SSEEvent struct {
	Event string
	Data  string
	ID    string
	Retry string
}

SSEEvent SSE事件

type SSEHandler

type SSEHandler interface {
	OnEvent(event *SSEEvent) error
	OnError(err error)
	OnComplete()
}

SSEHandler SSE事件处理器

Jump to

Keyboard shortcuts

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