client

package
v0.0.0-...-46ee16b Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client 聊天机器人客户端

func NewClient

func NewClient(config *Config) *Client

NewClient 创建新的客户端实例

func (*Client) ConnectWebSocket

func (c *Client) ConnectWebSocket() (*WSClient, error)

ConnectWebSocket 连接WebSocket服务器

func (*Client) GetMessageHistory

func (c *Client) GetMessageHistory(params MessageQueryParams) (*MessageQueryResult, error)

GetMessageHistory 获取消息历史

func (*Client) Login

func (c *Client) Login(email, password string) error

Login 用户登录

func (*Client) RefreshToken

func (c *Client) RefreshToken() error

RefreshToken 刷新token

func (*Client) Register

func (c *Client) Register(email, password, name string) error

Register 注册新用户

func (*Client) SendMessage

func (c *Client) SendMessage(msgType string, content interface{}) error

SendMessage 发送消息

func (*Client) SendText

func (c *Client) SendText(text string) error

SendText 发送文本消息

func (*Client) UpdatePassword

func (c *Client) UpdatePassword(oldPassword, newPassword string) error

UpdatePassword 更新密码

func (*Client) UpdateProfile

func (c *Client) UpdateProfile(name string) error

UpdateProfile 更新用户资料

type Config

type Config struct {
	BaseURL   string        // API基础URL
	Timeout   time.Duration // HTTP请求超时时间
	AuthToken string        // JWT认证token
	UserAgent string        // User-Agent
	Debug     bool          // 是否开启调试模式
}

Config 客户端配置

type ErrorResponse

type ErrorResponse struct {
	Code     int    `json:"code"`
	Message  string `json:"message"`
	ErrorMsg string `json:"error,omitempty"`
}

ErrorResponse API错误响应

func (*ErrorResponse) Error

func (e *ErrorResponse) Error() string

type HeartbeatConfig

type HeartbeatConfig struct {
	MinInterval     time.Duration
	MaxInterval     time.Duration
	InitialInterval time.Duration
	AdjustFactor    float64
	RTTThreshold    time.Duration
}

HeartbeatConfig 心跳配置

type LoginRequest

type LoginRequest struct {
	Email    string `json:"email"`
	Password string `json:"password"`
}

LoginRequest 登录请求参数

type Message

type Message struct {
	ID        uint            `json:"id"`
	Content   string          `json:"content"`
	Type      string          `json:"type"`
	Sender    string          `json:"sender"`
	Seq       uint            `json:"seq"`
	SessionID uint            `json:"session_id"`
	Extra     json.RawMessage `json:"extra,omitempty"`
	CreatedAt Time            `json:"created_at"`
}

Message 消息结构

type MessageHandler

type MessageHandler func(message []byte)

MessageHandler 消息处理函数类型

type MessageQueryParams

type MessageQueryParams struct {
	SessionID *uint     `json:"session_id,omitempty"`
	StartTime time.Time `json:"start_time,omitempty"`
	EndTime   time.Time `json:"end_time,omitempty"`
	Page      int       `json:"page,omitempty"`
	PageSize  int       `json:"page_size,omitempty"`
}

MessageQueryParams 消息查询参数

type MessageQueryResult

type MessageQueryResult struct {
	Total    int64     `json:"total"`
	Messages []Message `json:"messages"`
}

MessageQueryResult 消息查询结果

type RegisterRequest

type RegisterRequest struct {
	Email    string `json:"email"`
	Password string `json:"password"`
	Name     string `json:"name"`
}

RegisterRequest 注册请求参数

type TextMessage

type TextMessage struct {
	Text string `json:"text"`
}

TextMessage 文本消息

type Time

type Time time.Time

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

func (Time) String

func (t Time) String() string

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(data []byte) (err error)

type TokenResponse

type TokenResponse struct {
	Token string `json:"token"`
}

TokenResponse token响应

type UpdatePasswordRequest

type UpdatePasswordRequest struct {
	OldPassword string `json:"old_password"`
	NewPassword string `json:"new_password"`
}

UpdatePasswordRequest 更新密码请求参数

type UpdateProfileRequest

type UpdateProfileRequest struct {
	Name string `json:"name"`
}

UpdateProfileRequest 更新资料请求参数

type WSClient

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

WSClient WebSocket客户端

func (*WSClient) Close

func (ws *WSClient) Close()

Close 关闭连接

func (*WSClient) Listen

func (ws *WSClient) Listen(handler MessageHandler)

Listen 监听消息

func (*WSClient) Receive

func (ws *WSClient) Receive(ctx context.Context) ([]byte, error)

Receive 接收消息

func (*WSClient) Send

func (ws *WSClient) Send(msgType string, content interface{}) error

Send 发送消息

func (*WSClient) SendText

func (ws *WSClient) SendText(text string) error

SendText 发送文本消息

Jump to

Keyboard shortcuts

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