Documentation
¶
Index ¶
- Variables
- func BackupStorage(store ChatAppMessageStore, backupPath string) error
- func BuildSessionID(platform, userID, channelID string) string
- func ExportToJSON(store ChatAppMessageStore, outputPath string, query *MessageQuery) error
- func FormatTimestamp(t time.Time) string
- func GenerateProviderSessionID() string
- func ImportFromJSON(store ChatAppMessageStore, inputPath string) (int, error)
- func IsConfigError(err error) bool
- func IsConnectionError(err error) bool
- func IsNotFound(err error) bool
- func MaskSensitiveData(data string) string
- func ParseMessageType(s string) string
- func SanitizeContent(content string, maxLength int) string
- func TruncateForLog(content string, maxLen int) string
- func ValidateMessage(msg *ChatAppMessage) error
- type ChatAppMessage
- type ChatAppMessageStore
- type Check
- type ConfigLoader
- type DefaultStrategy
- type HealthCheckResult
- type HealthChecker
- type MemoryFactory
- type MemoryStorage
- func (m *MemoryStorage) Close() error
- func (m *MemoryStorage) Count(ctx context.Context, query *MessageQuery) (int64, error)
- func (m *MemoryStorage) DeleteSession(ctx context.Context, chatSessionID string) error
- func (m *MemoryStorage) Get(ctx context.Context, messageID string) (*ChatAppMessage, error)
- func (m *MemoryStorage) GetSessionMeta(ctx context.Context, chatSessionID string) (*SessionMeta, error)
- func (m *MemoryStorage) GetStrategy() StorageStrategy
- func (m *MemoryStorage) Initialize(ctx context.Context) error
- func (m *MemoryStorage) List(ctx context.Context, query *MessageQuery) ([]*ChatAppMessage, error)
- func (m *MemoryStorage) ListUserSessions(ctx context.Context, platform, userID string) ([]string, error)
- func (m *MemoryStorage) Name() string
- func (m *MemoryStorage) SetStrategy(s StorageStrategy) error
- func (m *MemoryStorage) StoreBotResponse(ctx context.Context, msg *ChatAppMessage) error
- func (m *MemoryStorage) StoreUserMessage(ctx context.Context, msg *ChatAppMessage) error
- func (m *MemoryStorage) Version() string
- type MessageQuery
- type PluginConfig
- type PluginFactory
- type PluginRegistry
- type PostgreFactory
- type PostgreSQLConfig
- type PostgreStorage
- func (p *PostgreStorage) Close() error
- func (p *PostgreStorage) Count(ctx context.Context, query *MessageQuery) (int64, error)
- func (p *PostgreStorage) DeleteSession(ctx context.Context, chatSessionID string) error
- func (p *PostgreStorage) Get(ctx context.Context, messageID string) (*ChatAppMessage, error)
- func (p *PostgreStorage) GetSessionMeta(ctx context.Context, chatSessionID string) (*SessionMeta, error)
- func (p *PostgreStorage) GetStrategy() StorageStrategy
- func (p *PostgreStorage) Initialize(ctx context.Context) error
- func (p *PostgreStorage) List(ctx context.Context, query *MessageQuery) ([]*ChatAppMessage, error)
- func (p *PostgreStorage) ListUserSessions(ctx context.Context, platform, userID string) ([]string, error)
- func (p *PostgreStorage) Name() string
- func (p *PostgreStorage) SetStrategy(s StorageStrategy) error
- func (p *PostgreStorage) StoreBotResponse(ctx context.Context, msg *ChatAppMessage) error
- func (p *PostgreStorage) StoreUserMessage(ctx context.Context, msg *ChatAppMessage) error
- func (p *PostgreStorage) Version() string
- type ReadOnlyStore
- type SQLiteConfig
- type SQLiteFactory
- type SQLiteStorage
- func (s *SQLiteStorage) Close() error
- func (s *SQLiteStorage) Count(ctx context.Context, query *MessageQuery) (int64, error)
- func (s *SQLiteStorage) DeleteSession(ctx context.Context, chatSessionID string) error
- func (s *SQLiteStorage) Get(ctx context.Context, messageID string) (*ChatAppMessage, error)
- func (s *SQLiteStorage) GetSessionMeta(ctx context.Context, chatSessionID string) (*SessionMeta, error)
- func (s *SQLiteStorage) GetStrategy() StorageStrategy
- func (s *SQLiteStorage) Initialize(ctx context.Context) error
- func (s *SQLiteStorage) List(ctx context.Context, query *MessageQuery) ([]*ChatAppMessage, error)
- func (s *SQLiteStorage) ListUserSessions(ctx context.Context, platform, userID string) ([]string, error)
- func (s *SQLiteStorage) Name() string
- func (s *SQLiteStorage) SetStrategy(st StorageStrategy) error
- func (s *SQLiteStorage) StoreBotResponse(ctx context.Context, msg *ChatAppMessage) error
- func (s *SQLiteStorage) StoreUserMessage(ctx context.Context, msg *ChatAppMessage) error
- func (s *SQLiteStorage) Version() string
- type SessionMeta
- type SessionStore
- type StorageConfig
- type StorageError
- type StorageMetrics
- type StorageStrategy
- type StreamingConfig
- type WriteOnlyStore
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("message not found") ErrSessionNotFound = errors.New("session not found") ErrInvalidMessage = errors.New("invalid message") ErrStorageNotEnabled = errors.New("storage not enabled") ErrConnectionFailed = errors.New("database connection failed") ErrQueryFailed = errors.New("query execution failed") ErrStoreFailed = errors.New("message store failed") ErrInvalidConfig = errors.New("invalid storage configuration") ErrUnsupportedType = errors.New("unsupported storage type") ErrSessionClosed = errors.New("storage session closed") ErrTransactionFailed = errors.New("transaction failed") )
Common storage errors
Functions ¶
func BackupStorage ¶
func BackupStorage(store ChatAppMessageStore, backupPath string) error
BackupStorage 备份存储
func BuildSessionID ¶
BuildSessionID 构建会话ID
func ExportToJSON ¶
func ExportToJSON(store ChatAppMessageStore, outputPath string, query *MessageQuery) error
ExportToJSON 将消息导出为 JSON
func GenerateProviderSessionID ¶
func GenerateProviderSessionID() string
GenerateProviderSessionID 生成 Provider 会话ID
func ImportFromJSON ¶
func ImportFromJSON(store ChatAppMessageStore, inputPath string) (int, error)
ImportFromJSON 从 JSON 导入消息
func SanitizeContent ¶
SanitizeContent 清理消息内容
Types ¶
type ChatAppMessage ¶
type ChatAppMessage struct {
ID string
ChatSessionID string
ChatPlatform string
ChatUserID string
ChatBotUserID string
ChatChannelID string
ChatThreadID string
EngineSessionID uuid.UUID
EngineNamespace string
ProviderSessionID string
ProviderType string
MessageType types.MessageType
FromUserID string
FromUserName string
ToUserID string
Content string
Metadata map[string]any
CreatedAt time.Time
UpdatedAt time.Time
Deleted bool
DeletedAt *time.Time
}
ChatAppMessage 存储层消息实体
type ChatAppMessageStore ¶
type ChatAppMessageStore interface {
ReadOnlyStore
WriteOnlyStore
SessionStore
Initialize(ctx context.Context) error
Close() error
Name() string
Version() string
}
ChatAppMessageStore 完整接口
type Check ¶
type Check struct {
Status string `json:"status"` // pass, fail, warn
Message string `json:"message"`
Latency time.Duration `json:"latency"`
}
Check 单项检查结果
type ConfigLoader ¶
type ConfigLoader struct {
// contains filtered or unexported fields
}
ConfigLoader 配置加载器
func (*ConfigLoader) LoadStorageConfig ¶
func (l *ConfigLoader) LoadStorageConfig() (*StorageConfig, error)
LoadStorageConfig 从 YAML 文件加载存储配置
type DefaultStrategy ¶
type DefaultStrategy struct{}
DefaultStrategy 默认策略
func NewDefaultStrategy ¶
func NewDefaultStrategy() *DefaultStrategy
func (*DefaultStrategy) AfterStore ¶
func (s *DefaultStrategy) AfterStore(ctx context.Context, msg *ChatAppMessage) error
func (*DefaultStrategy) BeforeStore ¶
func (s *DefaultStrategy) BeforeStore(ctx context.Context, msg *ChatAppMessage) error
func (*DefaultStrategy) ShouldStore ¶
func (s *DefaultStrategy) ShouldStore(msg *ChatAppMessage) bool
type HealthCheckResult ¶
type HealthCheckResult struct {
Status string `json:"status"` // healthy, degraded, unhealthy
Latency time.Duration `json:"latency"`
Timestamp time.Time `json:"timestamp"`
Checks map[string]Check `json:"checks"`
}
HealthCheckResult 健康检查结果
func DefaultHealthCheck ¶
func DefaultHealthCheck(store ChatAppMessageStore) *HealthCheckResult
DefaultHealthCheck 执行默认健康检查
type HealthChecker ¶
type HealthChecker interface {
HealthCheck(ctx context.Context) (*HealthCheckResult, error)
}
HealthChecker 健康检查接口
type MemoryFactory ¶
type MemoryFactory struct{}
func (*MemoryFactory) Create ¶
func (f *MemoryFactory) Create(config PluginConfig) (ChatAppMessageStore, error)
type MemoryStorage ¶
type MemoryStorage struct {
// contains filtered or unexported fields
}
MemoryStorage 内存存储实现
func (*MemoryStorage) Close ¶
func (m *MemoryStorage) Close() error
func (*MemoryStorage) Count ¶
func (m *MemoryStorage) Count(ctx context.Context, query *MessageQuery) (int64, error)
func (*MemoryStorage) DeleteSession ¶
func (m *MemoryStorage) DeleteSession(ctx context.Context, chatSessionID string) error
func (*MemoryStorage) Get ¶
func (m *MemoryStorage) Get(ctx context.Context, messageID string) (*ChatAppMessage, error)
func (*MemoryStorage) GetSessionMeta ¶
func (m *MemoryStorage) GetSessionMeta(ctx context.Context, chatSessionID string) (*SessionMeta, error)
func (*MemoryStorage) GetStrategy ¶
func (m *MemoryStorage) GetStrategy() StorageStrategy
func (*MemoryStorage) Initialize ¶
func (m *MemoryStorage) Initialize(ctx context.Context) error
func (*MemoryStorage) List ¶
func (m *MemoryStorage) List(ctx context.Context, query *MessageQuery) ([]*ChatAppMessage, error)
func (*MemoryStorage) ListUserSessions ¶
func (*MemoryStorage) Name ¶
func (m *MemoryStorage) Name() string
func (*MemoryStorage) SetStrategy ¶
func (m *MemoryStorage) SetStrategy(s StorageStrategy) error
func (*MemoryStorage) StoreBotResponse ¶
func (m *MemoryStorage) StoreBotResponse(ctx context.Context, msg *ChatAppMessage) error
func (*MemoryStorage) StoreUserMessage ¶
func (m *MemoryStorage) StoreUserMessage(ctx context.Context, msg *ChatAppMessage) error
func (*MemoryStorage) Version ¶
func (m *MemoryStorage) Version() string
type MessageQuery ¶
type MessageQuery struct {
ChatSessionID string
EngineSessionID uuid.UUID
ProviderType string
ProviderSessionID string
StartTime *time.Time
EndTime *time.Time
MessageTypes []types.MessageType
Limit int
Offset int
Ascending bool
IncludeDeleted bool
}
MessageQuery 消息查询条件
type PluginFactory ¶
type PluginFactory interface {
Create(config PluginConfig) (ChatAppMessageStore, error)
}
PluginFactory 插件工厂接口
type PluginRegistry ¶
type PluginRegistry struct {
// contains filtered or unexported fields
}
PluginRegistry 插件注册表
func GlobalRegistry ¶
func GlobalRegistry() *PluginRegistry
func NewPluginRegistry ¶
func NewPluginRegistry() *PluginRegistry
func (*PluginRegistry) Get ¶
func (r *PluginRegistry) Get(name string, config PluginConfig) (ChatAppMessageStore, error)
func (*PluginRegistry) List ¶
func (r *PluginRegistry) List() []string
func (*PluginRegistry) Register ¶
func (r *PluginRegistry) Register(name string, factory PluginFactory)
type PostgreFactory ¶
type PostgreFactory struct{}
PostgreFactory PostgreSQL 工厂
func (*PostgreFactory) Create ¶
func (f *PostgreFactory) Create(config PluginConfig) (ChatAppMessageStore, error)
type PostgreSQLConfig ¶
type PostgreSQLConfig struct {
Host string
Port int
User string
Password string
Database string
SSLMode string
MaxOpenConns int
MaxIdleConns int
MaxLifetime time.Duration
}
PostgreSQLConfig PostgreSQL 配置
type PostgreStorage ¶
type PostgreStorage struct {
// contains filtered or unexported fields
}
PostgreStorage PostgreSQL 存储实现 (Level 2: Partitioned for 100M+ rows)
func NewPostgreStorage ¶
func NewPostgreStorage(pgConfig PostgreSQLConfig, pluginConfig PluginConfig) (*PostgreStorage, error)
NewPostgreStorage 创建 PostgreSQL 存储
func (*PostgreStorage) Count ¶
func (p *PostgreStorage) Count(ctx context.Context, query *MessageQuery) (int64, error)
Count 统计消息数量
func (*PostgreStorage) DeleteSession ¶
func (p *PostgreStorage) DeleteSession(ctx context.Context, chatSessionID string) error
DeleteSession 删除会话
func (*PostgreStorage) Get ¶
func (p *PostgreStorage) Get(ctx context.Context, messageID string) (*ChatAppMessage, error)
Get 根据 ID 获取消息
func (*PostgreStorage) GetSessionMeta ¶
func (p *PostgreStorage) GetSessionMeta(ctx context.Context, chatSessionID string) (*SessionMeta, error)
GetSessionMeta 获取会话元数据
func (*PostgreStorage) GetStrategy ¶
func (p *PostgreStorage) GetStrategy() StorageStrategy
GetStrategy 获取存储策略
func (*PostgreStorage) Initialize ¶
func (p *PostgreStorage) Initialize(ctx context.Context) error
Initialize 初始化数据库表结构
func (*PostgreStorage) List ¶
func (p *PostgreStorage) List(ctx context.Context, query *MessageQuery) ([]*ChatAppMessage, error)
List 查询消息列表
func (*PostgreStorage) ListUserSessions ¶
func (p *PostgreStorage) ListUserSessions(ctx context.Context, platform, userID string) ([]string, error)
ListUserSessions 列出用户的所有会话
func (*PostgreStorage) SetStrategy ¶
func (p *PostgreStorage) SetStrategy(s StorageStrategy) error
SetStrategy 设置存储策略
func (*PostgreStorage) StoreBotResponse ¶
func (p *PostgreStorage) StoreBotResponse(ctx context.Context, msg *ChatAppMessage) error
StoreBotResponse 存储机器人响应
func (*PostgreStorage) StoreUserMessage ¶
func (p *PostgreStorage) StoreUserMessage(ctx context.Context, msg *ChatAppMessage) error
StoreUserMessage 存储用户消息
type ReadOnlyStore ¶
type ReadOnlyStore interface {
Get(ctx context.Context, messageID string) (*ChatAppMessage, error)
List(ctx context.Context, query *MessageQuery) ([]*ChatAppMessage, error)
Count(ctx context.Context, query *MessageQuery) (int64, error)
}
ReadOnlyStore 只读接口 (ISP)
type SQLiteConfig ¶
SQLiteConfig SQLite 配置
type SQLiteFactory ¶
type SQLiteFactory struct{}
func (*SQLiteFactory) Create ¶
func (f *SQLiteFactory) Create(config PluginConfig) (ChatAppMessageStore, error)
type SQLiteStorage ¶
type SQLiteStorage struct {
// contains filtered or unexported fields
}
SQLiteStorage SQLite 存储实现
func (*SQLiteStorage) Close ¶
func (s *SQLiteStorage) Close() error
func (*SQLiteStorage) Count ¶
func (s *SQLiteStorage) Count(ctx context.Context, query *MessageQuery) (int64, error)
func (*SQLiteStorage) DeleteSession ¶
func (s *SQLiteStorage) DeleteSession(ctx context.Context, chatSessionID string) error
func (*SQLiteStorage) Get ¶
func (s *SQLiteStorage) Get(ctx context.Context, messageID string) (*ChatAppMessage, error)
func (*SQLiteStorage) GetSessionMeta ¶
func (s *SQLiteStorage) GetSessionMeta(ctx context.Context, chatSessionID string) (*SessionMeta, error)
func (*SQLiteStorage) GetStrategy ¶
func (s *SQLiteStorage) GetStrategy() StorageStrategy
func (*SQLiteStorage) Initialize ¶
func (s *SQLiteStorage) Initialize(ctx context.Context) error
func (*SQLiteStorage) List ¶
func (s *SQLiteStorage) List(ctx context.Context, query *MessageQuery) ([]*ChatAppMessage, error)
func (*SQLiteStorage) ListUserSessions ¶
func (*SQLiteStorage) Name ¶
func (s *SQLiteStorage) Name() string
func (*SQLiteStorage) SetStrategy ¶
func (s *SQLiteStorage) SetStrategy(st StorageStrategy) error
func (*SQLiteStorage) StoreBotResponse ¶
func (s *SQLiteStorage) StoreBotResponse(ctx context.Context, msg *ChatAppMessage) error
func (*SQLiteStorage) StoreUserMessage ¶
func (s *SQLiteStorage) StoreUserMessage(ctx context.Context, msg *ChatAppMessage) error
func (*SQLiteStorage) Version ¶
func (s *SQLiteStorage) Version() string
type SessionMeta ¶
type SessionMeta struct {
ChatSessionID string
ChatPlatform string
ChatUserID string
LastMessageID string
LastMessageAt time.Time
MessageCount int64
UpdatedAt time.Time
}
SessionMeta 会话元数据
type SessionStore ¶
type SessionStore interface {
GetSessionMeta(ctx context.Context, chatSessionID string) (*SessionMeta, error)
ListUserSessions(ctx context.Context, platform, userID string) ([]string, error)
DeleteSession(ctx context.Context, chatSessionID string) error
}
SessionStore 会话管理接口
type StorageConfig ¶
type StorageConfig struct {
Enabled bool `json:"enabled"`
Type string `json:"type"`
SQLite SQLiteConfig `json:"sqlite"`
PostgreSQL PostgreSQLConfig `json:"postgres"`
Strategy string `json:"strategy"`
Streaming StreamingConfig `json:"streaming"`
}
StorageConfig 存储配置
type StorageError ¶
StorageError 存储错误结构
func NewStorageError ¶
func NewStorageError(code, message string, err error) *StorageError
NewStorageError 创建新的存储错误
func (*StorageError) Error ¶
func (e *StorageError) Error() string
func (*StorageError) Unwrap ¶
func (e *StorageError) Unwrap() error
type StorageMetrics ¶
type StorageMetrics struct {
TotalMessages int64 `json:"total_messages"`
TotalSessions int64 `json:"total_sessions"`
StorageSizeBytes int64 `json:"storage_size_bytes"`
Uptime time.Duration `json:"uptime"`
}
StorageMetrics 存储指标
func GetMetrics ¶
func GetMetrics(store ChatAppMessageStore) (*StorageMetrics, error)
GetMetrics 获取存储指标
type StorageStrategy ¶
type StorageStrategy interface {
ShouldStore(msg *ChatAppMessage) bool
BeforeStore(ctx context.Context, msg *ChatAppMessage) error
AfterStore(ctx context.Context, msg *ChatAppMessage) error
}
StorageStrategy 存储策略接口 (OCP)
type StreamingConfig ¶
type StreamingConfig struct {
Enabled bool `json:"enabled"`
BufferSize int `json:"buffer_size"`
TimeoutSec int `json:"timeout_seconds"`
StoragePolicy string `json:"storage_policy"`
}
StreamingConfig 流式配置
type WriteOnlyStore ¶
type WriteOnlyStore interface {
StoreUserMessage(ctx context.Context, msg *ChatAppMessage) error
StoreBotResponse(ctx context.Context, msg *ChatAppMessage) error
}
WriteOnlyStore 只写接口 (ISP)