messagerepo

package
v0.0.0-...-65c93a7 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

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) Delete

func (idx *Index) Delete(ctx context.Context, id string) error

Delete removes a chat message from storage.

func (*Index) Save

func (idx *Index) Save(ctx context.Context, msg Message) error

Save persists a single chat message.

func (*Index) Search

func (idx *Index) Search(ctx context.Context, query string, startTime, endTime *time.Time, filterSource, filterType string, page, pageSize int, sortField, sortOrder string) ([]Message, int64, int64, error)

func (*Index) SearchByID

func (idx *Index) SearchByID(ctx context.Context, id string) (Message, error)

SearchByID retrieves a chat message by its unique identifier.

func (*Index) Update

func (idx *Index) Update(ctx context.Context, id string, update MessageUpdate) error

Update modifies specific fields of an existing chat message.

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.

func New

func New(ctx context.Context, opensearchURL, indexName string, responseTimeout time.Duration) (Store, error)

New creates a new Courier instance by initializing the underlying storage client. It performs an initial connection test and ensures the necessary index is available.

func NewTestStore

func NewTestStore(t *testing.T) (Store, func(), error)

NewTestStore initializes an Index instance backed by a test container. This is intended for integration testing purposes.

Jump to

Keyboard shortcuts

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