Documentation
¶
Index ¶
- Variables
- type Index
- func (idx *Index) Delete(ctx context.Context, id string) error
- func (idx *Index) Save(ctx context.Context, msg Message) error
- func (idx *Index) Search(ctx context.Context, query string, startTime, endTime *time.Time, ...) ([]Message, int64, int64, error)
- func (idx *Index) SearchByID(ctx context.Context, id string) (Message, error)
- func (idx *Index) Update(ctx context.Context, id string, update MessageUpdate) error
- type Message
- type MessageUpdate
- type Store
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // Serialization/deserialization errors. ErrSerializeMessage = errors.New("messagerepo: failed to serialize message") ErrDeserializeResponse = errors.New("messagerepo: failed to deserialize response") // Index-related errors. ErrIndexCreationFailed = errors.New("messagerepo: failed to create index") ErrIndexCheckFailed = errors.New("messagerepo: failed to check index existence") // Document retrieval errors. ErrMessageNotFound = errors.New("messagerepo: message not found") // Operation errors. ErrSearchFailed = errors.New("messagerepo: search failed") ErrUpdateFailed = errors.New("messagerepo: update failed") ErrDeleteFailed = errors.New("messagerepo: delete failed") )
Functions ¶
This section is empty.
Types ¶
type Index ¶
type Index struct {
*opensearch.Client
IndexName string
}
Index is a concrete implementation of Courier using an underlying document store. It wraps an OpenSearch client to perform document operations.
func (*Index) SearchByID ¶
SearchByID retrieves a chat message by its unique identifier.
type Message ¶
type Message struct {
ID string `json:"id"`
MessageID string `json:"messageId"`
SpecVersion string `json:"specversion"`
Type string `json:"type"`
Time time.Time `json:"time"`
Subject string `json:"subject"`
Source string `json:"source"`
Data string `json:"data"`
ReceivedAt time.Time `json:"receivedAt"`
}
type MessageUpdate ¶
type MessageUpdate struct {
Subject *string `json:"subject,omitempty"`
Data *string `json:"data,omitempty"`
}
MessageUpdate defines the updatable fields for a Message. Fields that are nil will be omitted in the update.
type Store ¶
type Store interface {
// Save persists a chat message.
Save(ctx context.Context, msg Message) error
// SearchByID retrieves a chat message by its unique identifier.
SearchByID(ctx context.Context, id string) (Message, error)
// Search queries chat messages based on various criteria.
// Parameters:
// - query: text to match within the message subject (if empty, all messages are returned)
// - startTime, endTime: optional time range filters for the message timestamp
// - filterSource, filterType: optional exact-match filters for source and type fields
// - page, pageSize: pagination parameters (page is 1-based; if pageSize==0 then pagination is ignored)
// - sortField, sortOrder: sorting parameters (defaults are applied if empty)
//
// Returns:
// - a slice of messages matching the query
// - the total number of matching messages
// - the query execution duration in milliseconds
Search(ctx context.Context, query string, startTime, endTime *time.Time, filterSource, filterType string, page, pageSize int, sortField, sortOrder string) ([]Message, int64, int64, error)
// Update modifies specified fields of a stored chat message.
Update(ctx context.Context, id string, update MessageUpdate) error
// Delete removes a chat message from storage.
Delete(ctx context.Context, id string) error
}
Store defines the operations for persisting and retrieving chat messages. Implementations should adhere to these behaviors without exposing internal details.
Click to show internal directories.
Click to hide internal directories.