Documentation
¶
Overview ¶
Package watermillchat provides live hypermedia chat for <watermill.io> event caster. Messages are delivered as server side events.
Index ¶
- Constants
- func Batch[T any](in <-chan T, limit int, flush time.Duration) (out chan []T)
- func ContextWithIdentity(parent context.Context, id Identity) context.Context
- type Broadcast
- type Chat
- type Configuration
- type HistoryConfiguration
- type HistoryRepository
- type Identity
- type Message
- type Room
- type VoidHistoryRepository
- type WatermillConfiguration
Constants ¶
View Source
const ( DefaultWatermillTopic = "watermillchat" DefaultHistoryMostMessagesPerRoom = 1000 DefaultHistoryDepth = DefaultHistoryMostMessagesPerRoom // TODO: deprecate DefaultHistoryRetention = time.Minute * 60 * 24 // 24 hours DefaultHistoryCleanupFrequency = time.Minute * 15 DefaultCleanupFrequency = DefaultHistoryCleanupFrequency // TODO: deprecate )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Chat ¶
type Chat struct {
// contains filtered or unexported fields
}
type Configuration ¶ added in v0.0.5
type Configuration struct {
Watermill WatermillConfiguration
History HistoryConfiguration
Logger *slog.Logger
}
func (Configuration) Validate ¶ added in v0.0.5
func (c Configuration) Validate() (err error)
type HistoryConfiguration ¶ added in v0.0.5
type HistoryConfiguration struct {
// Defaults to [VoidHistoryRepository].
Repository HistoryRepository
// Retention constraints the life time of messages before their deletion.
// Defaults to [DefaultHistoryRetention].
Retention time.Duration
// CleanUpFrequency is the pause between message purge
// cycles based on retention. Defaults to [DefaultHistoryCleanupFrequency].
CleanUpFrequency time.Duration
// MostMessagesPerRoom constraints the maximum number of
// returned messages per room when history is loaded using. More messages may still
// be present in the database, if they retention duration
// has not yet run out. Defaults to [DefaultHistoryMostMessagesPerRoom].
MostMessagesPerRoom int
}
type HistoryRepository ¶
type HistoryRepository interface {
Listen(broadcasts <-chan *message.Message)
GetRoomMessages(context.Context, string) ([]Message, error)
}
History is a list of messages grouped by room name. Must be sorted in ascending order by [Message.CreatedAt]. Apply to Chat using [WithHistory] option.
type VoidHistoryRepository ¶
type VoidHistoryRepository struct{}
func (VoidHistoryRepository) GetRoomMessages ¶ added in v0.0.2
func (VoidHistoryRepository) Listen ¶
func (r VoidHistoryRepository) Listen(broadcasts <-chan *message.Message)
type WatermillConfiguration ¶ added in v0.0.5
type WatermillConfiguration struct {
// Topic where the messages are published to and read from.
// Defaults to [DefaultWatermillTopic].
Topic string
Publisher message.Publisher
Subscriber message.Subscriber
}
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
basic
command
|
|
|
datastar
command
|
|
|
sqlite
module
|
|
|
history
|
|
|
sqlitehistory
module
|
|
|
Package httpmux injects front-end routing paths into a http.ServeMux for rendering watermillchat.Chat view.
|
Package httpmux injects front-end routing paths into a http.ServeMux for rendering watermillchat.Chat view. |
|
hypermedia
Package hypermedia provides templates and [http.Handler]s for rendering chat sessions.
|
Package hypermedia provides templates and [http.Handler]s for rendering chat sessions. |
|
Package ollama provides a generative chat bot.
|
Package ollama provides a generative chat bot. |
Click to show internal directories.
Click to hide internal directories.