Documentation
¶
Index ¶
- Constants
- Variables
- func EncodeActionValue(action, sessionID, messageID string) (string, error)
- type APIError
- type ActionValue
- type Adapter
- func (a *Adapter) GetAppToken() (string, error)
- func (a *Adapter) GetAppTokenWithContext(ctx context.Context) (string, error)
- func (a *Adapter) NewStreamWriter(ctx context.Context, userID, chatID, _ string) base.StreamWriter
- func (a *Adapter) SendMessage(ctx context.Context, sessionID string, msg *base.ChatMessage) error
- func (a *Adapter) SetSender(fn func(ctx context.Context, sessionID string, msg *base.ChatMessage) error)
- func (a *Adapter) Start(ctx context.Context) error
- func (a *Adapter) Stop() error
- type CardAction
- type CardBlock
- type CardBuilder
- func (b *CardBuilder) BuildAnswerCard(content string) (string, error)
- func (b *CardBuilder) BuildAnswerCardTemplate(content string) *CardTemplate
- func (b *CardBuilder) BuildErrorCard(errorMsg string) (string, error)
- func (b *CardBuilder) BuildPermissionCard(title, description, riskLevel string) (string, error)
- func (b *CardBuilder) BuildSessionStatsCard(duration string, tokenUsage int, otherStats map[string]string) (string, error)
- func (b *CardBuilder) BuildThinkingCard(message string) (string, error)
- func (b *CardBuilder) BuildToolUseCard(toolName, toolInput string) (string, error)
- type CardConfig
- type CardData
- type CardElement
- type CardHeader
- type CardTemplate
- type Client
- func (c *Client) CreateCard(ctx context.Context, token string, card *CardTemplate) (string, error)
- func (c *Client) GetAppToken() (string, int, error)
- func (c *Client) GetAppTokenWithContext(ctx context.Context) (string, int, error)
- func (c *Client) SendCardMessage(ctx context.Context, token, chatID, cardID string) (string, error)
- func (c *Client) SendInteractiveMessage(ctx context.Context, token, chatID, cardJSON string) (string, error)
- func (c *Client) SendMessage(ctx context.Context, token, chatID, msgType string, content map[string]string) (string, error)
- func (c *Client) SendTextMessage(ctx context.Context, token, chatID, text string) (string, error)
- func (c *Client) UpdateCard(ctx context.Context, token, cardID string, card *CardTemplate, sequence int) error
- type CommandContent
- type CommandEvent
- type CommandEventData
- type CommandHandler
- type CommandHeader
- type Config
- type CreateCardRequest
- type CreateCardResponse
- type Event
- type EventData
- type EventHandler
- func (h *EventHandler) HandleURLVerification(w http.ResponseWriter, token string, eventType string) bool
- func (h *EventHandler) ProcessEvent(w http.ResponseWriter, r *http.Request, ...)
- func (h *EventHandler) WriteJSONResponse(w http.ResponseWriter, data interface{})
- func (h *EventHandler) WriteOKResponse(w http.ResponseWriter)
- type EventHeader
- type FeishuAPIClient
- type InteractiveAction
- type InteractiveEvent
- type InteractiveEventData
- type InteractiveHandler
- type InteractiveHeader
- type InteractiveMessage
- type InteractiveUser
- type Message
- type MessageContent
- type MessageData
- type RateLimiter
- type SendMessageRequest
- type SendMessageResponse
- type StreamWriterStats
- type StreamingWriter
- func (w *StreamingWriter) CardID() string
- func (w *StreamingWriter) Close() error
- func (w *StreamingWriter) FallbackUsed() bool
- func (w *StreamingWriter) GetStats() StreamWriterStats
- func (w *StreamingWriter) IsClosed() bool
- func (w *StreamingWriter) IsStarted() bool
- func (w *StreamingWriter) MessageID() string
- func (w *StreamingWriter) MessageTS() string
- func (w *StreamingWriter) SetStoreCallback(callback func(content string))
- func (w *StreamingWriter) Write(p []byte) (n int, err error)
- type Text
- type TokenResponse
- type UpdateCardRequest
- type UpdateCardResponse
- type UserID
- type WebSocketClient
- func (c *WebSocketClient) Close() error
- func (c *WebSocketClient) Connect(ctx context.Context) error
- func (c *WebSocketClient) IsConnected() bool
- func (c *WebSocketClient) SetEventHandler(handler func(event *Event))
- func (c *WebSocketClient) SetOnConnect(callback func())
- func (c *WebSocketClient) SetOnDisconnect(callback func(error))
- type WebSocketData
- type WebSocketMessage
- type WebSocketResponse
Constants ¶
const ( CardTemplateBlue = "blue" CardTemplateWathet = "wathet" CardTemplateGreen = "green" CardTemplateYellow = "yellow" CardTemplateOrange = "orange" CardTemplateRed = "red" Purple = "purple" Grey = "grey" )
Card colors (templates)
const ( TextTypePlainText = "plain_text" TextTypeLarkMD = "lark_md" )
Text types
const ( ElementDiv = "div" ElementNote = "note" ElementAlert = "alert" ElementAction = "action" ElementButton = "button" ElementMarkdown = "markdown" )
Element types
const ( ButtonTypeDefault = "default" ButtonTypePrimary = "primary" ButtonTypeDanger = "danger" )
Button types
Variables ¶
var ( ErrConfigMissingAppID = fmt.Errorf("feishu: app_id is required") ErrConfigMissingAppSecret = fmt.Errorf("feishu: app_secret is required") ErrConfigMissingVerificationToken = fmt.Errorf("feishu: verification_token is required") ErrConfigMissingEncryptKey = fmt.Errorf("feishu: encrypt_key is required") ErrInvalidSignature = fmt.Errorf("feishu: invalid signature") ErrInvalidChallenge = fmt.Errorf("feishu: invalid challenge") ErrEventParseFailed = fmt.Errorf("feishu: failed to parse event") ErrUnsupportedEventType = fmt.Errorf("feishu: unsupported event type") ErrTokenFetchFailed = fmt.Errorf("feishu: failed to fetch access token") ErrMessageSendFailed = fmt.Errorf("feishu: failed to send message") ErrMessageUpdateFailed = fmt.Errorf("feishu: failed to update message") ErrMessageDeleteFailed = fmt.Errorf("feishu: failed to delete message") )
Feishu adapter errors
Functions ¶
func EncodeActionValue ¶
EncodeActionValue encodes an action value for button callback
Types ¶
type ActionValue ¶
type ActionValue struct {
Action string `json:"action"`
SessionID string `json:"session_id"`
MessageID string `json:"message_id,omitempty"`
}
ActionValue represents the decoded action value from button click
func DecodeActionValue ¶
func DecodeActionValue(value string) (*ActionValue, error)
DecodeActionValue decodes an action value from button callback
type Adapter ¶
Adapter implements the Feishu (Lark) chat adapter
func NewAdapter ¶
NewAdapter creates a new Feishu adapter
func (*Adapter) GetAppToken ¶
GetAppToken gets or caches the app access token
func (*Adapter) GetAppTokenWithContext ¶
GetAppTokenWithContext gets or caches the app access token with context
func (*Adapter) NewStreamWriter ¶ added in v0.31.0
NewStreamWriter creates a new streaming writer for Feishu messages This enables native streaming support via card entity updates
func (*Adapter) SendMessage ¶
SendMessage sends a message to Feishu
func (*Adapter) SetSender ¶
func (a *Adapter) SetSender(fn func(ctx context.Context, sessionID string, msg *base.ChatMessage) error)
SetSender sets the message sender function
type CardAction ¶
type CardAction struct {
Type string `json:"tag"`
Text *Text `json:"text,omitempty"`
Value interface{} `json:"value,omitempty"`
URL string `json:"url,omitempty"`
}
CardAction defines an interactive action (button, etc.)
type CardBlock ¶
type CardBlock struct {
Type string `json:"tag"`
Text *Text `json:"text,omitempty"`
Content string `json:"content,omitempty"`
Elements []CardElement `json:"elements,omitempty"`
Actions []CardAction `json:"actions,omitempty"`
}
CardBlock represents a card block
type CardBuilder ¶
type CardBuilder struct {
// contains filtered or unexported fields
}
CardBuilder builds Feishu interactive cards for HotPlex events
func NewCardBuilder ¶
func NewCardBuilder(sessionID string) *CardBuilder
NewCardBuilder creates a new card builder
func (*CardBuilder) BuildAnswerCard ¶
func (b *CardBuilder) BuildAnswerCard(content string) (string, error)
BuildAnswerCard builds an answer card with Markdown support Event: answer - Final answer with Markdown
func (*CardBuilder) BuildAnswerCardTemplate ¶ added in v0.31.0
func (b *CardBuilder) BuildAnswerCardTemplate(content string) *CardTemplate
BuildAnswerCardTemplate builds an answer card template without JSON marshaling This is more efficient when the card needs to be sent to APIs that accept CardTemplate structs
func (*CardBuilder) BuildErrorCard ¶
func (b *CardBuilder) BuildErrorCard(errorMsg string) (string, error)
BuildErrorCard builds an error/warning card Event: error - Red alert box
func (*CardBuilder) BuildPermissionCard ¶
func (b *CardBuilder) BuildPermissionCard(title, description, riskLevel string) (string, error)
BuildPermissionCard builds a permission request card with Allow/Deny buttons Event: permission_request - Interactive card with buttons
func (*CardBuilder) BuildSessionStatsCard ¶
func (b *CardBuilder) BuildSessionStatsCard(duration string, tokenUsage int, otherStats map[string]string) (string, error)
BuildSessionStatsCard builds a session statistics card Event: session_stats - Gray note with stats
func (*CardBuilder) BuildThinkingCard ¶
func (b *CardBuilder) BuildThinkingCard(message string) (string, error)
BuildThinkingCard builds a thinking state card Event: thinking - Shows "🤔 Thinking..." with loading animation
func (*CardBuilder) BuildToolUseCard ¶
func (b *CardBuilder) BuildToolUseCard(toolName, toolInput string) (string, error)
BuildToolUseCard builds a tool execution card Event: tool_use - Shows "🛠️ Executing: Bash"
type CardConfig ¶
type CardConfig struct {
WideScreenMode bool `json:"wide_screen_mode,omitempty"`
EnableForward bool `json:"enable_forward,omitempty"`
}
CardConfig defines card configuration
type CardData ¶ added in v0.31.0
type CardData struct {
CardID string `json:"card_id"`
}
CardData represents card data in response
type CardElement ¶
type CardElement struct {
Type string `json:"tag"`
Text *Text `json:"text,omitempty"`
Content string `json:"content,omitempty"`
Elements []CardElement `json:"elements,omitempty"`
Actions []CardAction `json:"actions,omitempty"`
}
CardElement represents a card element (markdown, note, alert, etc.)
type CardHeader ¶
type CardHeader struct {
Template string `json:"template,omitempty"`
Title *Text `json:"title,omitempty"`
}
CardHeader defines card header
type CardTemplate ¶
type CardTemplate struct {
Config *CardConfig `json:"config,omitempty"`
Header *CardHeader `json:"header,omitempty"`
Elements []CardElement `json:"elements,omitempty"`
Cards []CardBlock `json:"cards,omitempty"`
}
CardTemplate defines a Feishu interactive card template
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps the Feishu Open API
func (*Client) CreateCard ¶ added in v0.31.0
CreateCard creates a new card entity and returns card_id This is used for streaming: create card -> send card message -> update card
func (*Client) GetAppToken ¶
GetAppToken fetches a new app access token
func (*Client) GetAppTokenWithContext ¶
GetAppTokenWithContext fetches a new app access token with context
func (*Client) SendCardMessage ¶ added in v0.31.0
SendCardMessage sends a card message by card_id After creating a card entity, use this to send it to a chat
func (*Client) SendInteractiveMessage ¶
func (c *Client) SendInteractiveMessage(ctx context.Context, token, chatID, cardJSON string) (string, error)
SendInteractiveMessage sends an interactive card message This is a placeholder for Phase 2 implementation
func (*Client) SendMessage ¶
func (c *Client) SendMessage(ctx context.Context, token, chatID, msgType string, content map[string]string) (string, error)
SendMessage sends a message with specified type and content This is the generic message sending method for extensibility
func (*Client) SendTextMessage ¶
SendTextMessage sends a text message
func (*Client) UpdateCard ¶ added in v0.31.0
func (c *Client) UpdateCard(ctx context.Context, token, cardID string, card *CardTemplate, sequence int) error
UpdateCard updates an existing card entity with new content IMPORTANT: sequence must be strictly incrementing for each card_id
type CommandContent ¶
type CommandContent struct {
Text string `json:"text"`
}
CommandContent represents the command content
type CommandEvent ¶
type CommandEvent struct {
Header *CommandHeader `json:"header"`
Event *CommandEventData `json:"event"`
Token string `json:"token"`
}
CommandEvent represents a Feishu command event
type CommandEventData ¶
type CommandEventData struct {
AppID string `json:"app_id"`
TenantKey string `json:"tenant_key"`
OperatorID *UserID `json:"operator_id"`
Name string `json:"name"`
Content *CommandContent `json:"content"`
}
CommandEventData represents the command event data
type CommandHandler ¶
type CommandHandler struct {
// contains filtered or unexported fields
}
CommandHandler handles Feishu bot commands (/reset, /dc)
func NewCommandHandler ¶
func NewCommandHandler(adapter *Adapter, registry *command.Registry) *CommandHandler
NewCommandHandler creates a new command handler
func (*CommandHandler) HandleCommand ¶
func (h *CommandHandler) HandleCommand(w http.ResponseWriter, r *http.Request)
HandleCommand handles incoming command events
type CommandHeader ¶
type CommandHeader struct {
EventID string `json:"event_id"`
EventType string `json:"event_type"`
CreateTime string `json:"create_time"`
AppID string `json:"app_id"`
TenantKey string `json:"tenant_key"`
}
CommandHeader represents the command event header
type Config ¶
type Config struct {
// App credentials
AppID string `json:"app_id" yaml:"app_id"`
AppSecret string `json:"app_secret" yaml:"app_secret"`
// Event subscription
VerificationToken string `json:"verification_token" yaml:"verification_token"`
EncryptKey string `json:"encrypt_key" yaml:"encrypt_key"`
// Server configuration
ServerAddr string `json:"server_addr" yaml:"server_addr"`
MaxMessageLen int `json:"max_message_len" yaml:"max_message_len"`
// WebSocket configuration
UseWebSocket bool `json:"use_websocket" yaml:"use_websocket"` // 启用 WebSocket 长连接模式
// System prompt
SystemPrompt string `json:"system_prompt" yaml:"system_prompt"`
}
Config holds Feishu (Lark) adapter configuration
type CreateCardRequest ¶ added in v0.31.0
type CreateCardRequest struct {
Card *CardTemplate `json:"card"`
}
CreateCardRequest represents a card creation request
type CreateCardResponse ¶ added in v0.31.0
type CreateCardResponse struct {
Code int `json:"code"`
Msg string `json:"msg"`
Data *CardData `json:"data"`
}
CreateCardResponse represents a card creation response
type Event ¶
type Event struct {
Schema string `json:"schema"`
Header *EventHeader `json:"header"`
Event *EventData `json:"event"`
Token string `json:"token"`
Type string `json:"type"`
Challenge string `json:"challenge"`
}
Event represents a Feishu webhook event
type EventData ¶
type EventData struct {
Message *Message `json:"message"`
}
EventData contains the actual event payload
type EventHandler ¶
type EventHandler struct {
// contains filtered or unexported fields
}
EventHandler provides common event handling logic (DRY principle)
func NewEventHandler ¶
func NewEventHandler(adapter *Adapter) *EventHandler
NewEventHandler creates a new event handler
func (*EventHandler) HandleURLVerification ¶
func (h *EventHandler) HandleURLVerification(w http.ResponseWriter, token string, eventType string) bool
HandleURLVerification handles URL verification for Feishu webhooks
func (*EventHandler) ProcessEvent ¶
func (h *EventHandler) ProcessEvent(w http.ResponseWriter, r *http.Request, parseFunc func([]byte) (interface{}, error), handleFunc func(interface{}) error)
ProcessEvent is a common event processing pipeline
func (*EventHandler) WriteJSONResponse ¶
func (h *EventHandler) WriteJSONResponse(w http.ResponseWriter, data interface{})
WriteJSONResponse writes a JSON response
func (*EventHandler) WriteOKResponse ¶
func (h *EventHandler) WriteOKResponse(w http.ResponseWriter)
WriteOKResponse writes a simple OK response
type EventHeader ¶
type EventHeader struct {
EventType string `json:"event_type"`
EventID string `json:"event_id"`
CreateTime int64 `json:"create_time"`
TenantKey string `json:"tenant_key"`
AppID string `json:"app_id"`
}
EventHeader contains event metadata
type FeishuAPIClient ¶
type FeishuAPIClient interface {
GetAppTokenWithContext(ctx context.Context) (string, int, error)
SendMessage(ctx context.Context, token, chatID, msgType string, content map[string]string) (string, error)
SendTextMessage(ctx context.Context, token, chatID, text string) (string, error)
SendInteractiveMessage(ctx context.Context, token, chatID, cardJSON string) (string, error)
// Card API methods for streaming support
CreateCard(ctx context.Context, token string, card *CardTemplate) (string, error)
UpdateCard(ctx context.Context, token, cardID string, card *CardTemplate, sequence int) error
SendCardMessage(ctx context.Context, token, chatID, cardID string) (string, error)
}
FeishuAPIClient defines the interface for Feishu API operations (SOLID: Dependency Inversion)
type InteractiveAction ¶
InteractiveAction represents the button action
type InteractiveEvent ¶
type InteractiveEvent struct {
Header *InteractiveHeader `json:"header"`
Event *InteractiveEventData `json:"event"`
Token string `json:"token"`
}
InteractiveEvent represents a Feishu interactive event
type InteractiveEventData ¶
type InteractiveEventData struct {
Message *InteractiveMessage `json:"message"`
User *InteractiveUser `json:"user"`
Action *InteractiveAction `json:"action"`
}
InteractiveEventData represents the event data
type InteractiveHandler ¶
type InteractiveHandler struct {
// contains filtered or unexported fields
}
InteractiveHandler handles Feishu interactive card callbacks
func NewInteractiveHandler ¶
func NewInteractiveHandler(adapter *Adapter) *InteractiveHandler
NewInteractiveHandler creates a new interactive handler
func (*InteractiveHandler) HandleInteractive ¶
func (h *InteractiveHandler) HandleInteractive(w http.ResponseWriter, r *http.Request)
HandleInteractive handles incoming interactive events
func (*InteractiveHandler) UpdatePermissionCard ¶
func (h *InteractiveHandler) UpdatePermissionCard(ctx context.Context, messageID, chatID, result string) error
UpdatePermissionCard updates a permission card with the result
type InteractiveHeader ¶
type InteractiveHeader struct {
EventID string `json:"event_id"`
EventType string `json:"event_type"`
CreateTime string `json:"create_time"`
Token string `json:"token"`
AppID string `json:"app_id"`
TenantKey string `json:"tenant_key"`
}
InteractiveHeader represents the event header
type InteractiveMessage ¶
type InteractiveMessage struct {
MessageID string `json:"message_id"`
ChatID string `json:"chat_id"`
MessageType string `json:"message_type"`
}
InteractiveMessage represents the message in the event
type InteractiveUser ¶
type InteractiveUser struct {
UserID string `json:"user_id"`
}
InteractiveUser represents the user who triggered the event
type Message ¶
type Message struct {
MessageID string `json:"message_id"`
UnionID string `json:"union_id"`
SenderID string `json:"sender_id"`
ChatID string `json:"chat_id"`
Content *MessageContent `json:"content"`
CreateTime int64 `json:"create_time"`
TenantKey string `json:"tenant_key"`
MessageType string `json:"message_type"`
}
Message represents a Feishu message
type MessageContent ¶
MessageContent represents message content
type MessageData ¶
type MessageData struct {
MessageID string `json:"message_id"`
}
MessageData represents message data in response
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter implements simple rate limiting for commands
func NewRateLimiter ¶
func NewRateLimiter(duration time.Duration) *RateLimiter
NewRateLimiter creates a new rate limiter
func (*RateLimiter) Allow ¶
func (r *RateLimiter) Allow(key string) bool
Allow checks if a request is allowed
type SendMessageRequest ¶
type SendMessageRequest struct {
ReceiveID string `json:"receive_id"`
MsgType string `json:"msg_type"`
Content string `json:"content"`
}
SendMessageRequest represents a message send request
type SendMessageResponse ¶
type SendMessageResponse struct {
Code int `json:"code"`
Msg string `json:"msg"`
Data *MessageData `json:"data"`
}
SendMessageResponse represents a message send response
type StreamWriterStats ¶ added in v0.31.0
type StreamWriterStats struct {
BytesWritten int64 // 成功写入的总字节数
BytesFlushed int64 // 成功 flush 的总字节数
Sequence int // 当前序列号
IntegrityOK bool // 完整性检查是否通过
ContentLength int // 累积内容长度
}
StreamWriterStats 流式消息统计信息
type StreamingWriter ¶ added in v0.31.0
type StreamingWriter struct {
// contains filtered or unexported fields
}
StreamingWriter 实现 io.WriteCloser 接口,封装飞书卡片流式消息的生命周期管理 流程:首次 Write -> CreateCard -> SendCardMessage
后续 Write -> 累积到缓冲区 -> 后台 flushLoop -> UpdateCard (with sequence++) Close -> 最终 UpdateCard
func NewStreamingWriter ¶ added in v0.31.0
func NewStreamingWriter( ctx context.Context, adapter *Adapter, chatID string, onComplete func(messageID string), ) *StreamingWriter
NewStreamingWriter 创建新的流式写入器
func (*StreamingWriter) CardID ¶ added in v0.31.0
func (w *StreamingWriter) CardID() string
CardID 返回卡片实体 ID
func (*StreamingWriter) Close ¶ added in v0.31.0
func (w *StreamingWriter) Close() error
Close 结束流,更新最终内容并清理资源
func (*StreamingWriter) FallbackUsed ¶ added in v0.31.0
func (w *StreamingWriter) FallbackUsed() bool
FallbackUsed 返回是否使用了 fallback 机制 飞书的卡片更新没有编辑次数限制,因此不需要 fallback
func (*StreamingWriter) GetStats ¶ added in v0.31.0
func (w *StreamingWriter) GetStats() StreamWriterStats
GetStats 返回流统计信息
func (*StreamingWriter) IsClosed ¶ added in v0.31.0
func (w *StreamingWriter) IsClosed() bool
IsClosed 返回流是否已关闭
func (*StreamingWriter) IsStarted ¶ added in v0.31.0
func (w *StreamingWriter) IsStarted() bool
IsStarted 返回流是否已启动
func (*StreamingWriter) MessageID ¶ added in v0.31.0
func (w *StreamingWriter) MessageID() string
MessageID 返回流式消息的 ID
func (*StreamingWriter) MessageTS ¶ added in v0.31.0
func (w *StreamingWriter) MessageTS() string
MessageTS 返回消息时间戳(为了兼容 base.StreamWriter 接口,飞书使用 messageID)
func (*StreamingWriter) SetStoreCallback ¶ added in v0.31.0
func (w *StreamingWriter) SetStoreCallback(callback func(content string))
SetStoreCallback sets the callback to store the complete message content
type TokenResponse ¶
type TokenResponse struct {
Code int `json:"code"`
Msg string `json:"msg"`
AppAccessToken string `json:"app_access_token"`
Expire int `json:"expire"`
}
TokenResponse represents the app access token response
type UpdateCardRequest ¶ added in v0.31.0
type UpdateCardRequest struct {
Card *CardTemplate `json:"card"`
Sequence int `json:"sequence"`
}
UpdateCardRequest represents a card update request
type UpdateCardResponse ¶ added in v0.31.0
UpdateCardResponse represents a card update response
type UserID ¶
type UserID struct {
UserID string `json:"user_id"`
}
UserID represents a user identifier
type WebSocketClient ¶ added in v0.31.0
type WebSocketClient struct {
// contains filtered or unexported fields
}
WebSocketClient 封装飞书 WebSocket 长连接客户端
func NewWebSocketClient ¶ added in v0.31.0
func NewWebSocketClient(appID, appSecret string, apiClient FeishuAPIClient, logger *slog.Logger) *WebSocketClient
NewWebSocketClient 创建新的 WebSocket 客户端
func (*WebSocketClient) Close ¶ added in v0.31.0
func (c *WebSocketClient) Close() error
Close 关闭 WebSocket 连接
func (*WebSocketClient) Connect ¶ added in v0.31.0
func (c *WebSocketClient) Connect(ctx context.Context) error
Connect 建立 WebSocket 连接
func (*WebSocketClient) IsConnected ¶ added in v0.31.0
func (c *WebSocketClient) IsConnected() bool
IsConnected 返回当前连接状态
func (*WebSocketClient) SetEventHandler ¶ added in v0.31.0
func (c *WebSocketClient) SetEventHandler(handler func(event *Event))
SetEventHandler 设置事件处理回调
func (*WebSocketClient) SetOnConnect ¶ added in v0.31.0
func (c *WebSocketClient) SetOnConnect(callback func())
SetOnConnect 设置连接成功回调
func (*WebSocketClient) SetOnDisconnect ¶ added in v0.31.0
func (c *WebSocketClient) SetOnDisconnect(callback func(error))
SetOnDisconnect 设置断开连接回调
type WebSocketData ¶ added in v0.31.0
type WebSocketData struct {
URL string `json:"url"`
}
WebSocketData WebSocket 连接数据
type WebSocketMessage ¶ added in v0.31.0
type WebSocketMessage struct {
Type string `json:"type"`
Data json.RawMessage `json:"data"`
}
WebSocketMessage WebSocket 消息格式
type WebSocketResponse ¶ added in v0.31.0
type WebSocketResponse struct {
Code int `json:"code"`
Msg string `json:"msg"`
Data *WebSocketData `json:"data"`
}
WebSocketResponse 获取 WebSocket 连接地址的响应