Documentation
¶
Overview ¶
Package eventsink fans out core loop events to optional auxiliary destinations: a JSON Lines file/stream, a webhook URL, and/or a plain text log file. Sinks never block the engine — write errors are recorded on the sink and surfaced via Errors() so the caller can show them once the loop has finished.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Envelope ¶
type Envelope struct {
Type string `json:"type"`
Timestamp time.Time `json:"timestamp"`
Event any `json:"event"`
}
Envelope is the JSON shape used for both file and webhook output. The "type" field is the unqualified Go type name (e.g. "IterationStartEvent") to keep downstream consumers stable across refactors of the core package's import path.
type FanOut ¶
type FanOut struct {
// contains filtered or unexported fields
}
FanOut multiplexes events to several sinks. The zero value is ready to use; add sinks with Add and fan an event in via Write.
func (*FanOut) Add ¶
Add registers a sink. Nil sinks are ignored so callers can pass New*Sink results directly without nil-checking.
type JSONSink ¶
type JSONSink struct {
// contains filtered or unexported fields
}
JSONSink writes one Envelope per line to the underlying writer. It is safe for concurrent use and flushes on every write so a crash never loses more than the in-flight event.
func NewJSONFileSink ¶
NewJSONFileSink opens path for writing (truncating) and returns a sink that closes the file on Close.
func NewJSONSink ¶
NewJSONSink wraps an existing writer (e.g. os.Stdout) as a sink. The writer is not closed on Close.
type LogFileSink ¶
type LogFileSink struct {
// contains filtered or unexported fields
}
LogFileSink mirrors any string-formattable event to a plain text file. It records each event as "<timestamp> <Type>" plus a per-type one-line summary, suitable for grepping. Detailed payloads belong in JSON.
func NewLogFileSink ¶
func NewLogFileSink(path string) (*LogFileSink, error)
NewLogFileSink opens path for append (creating if missing).
func (*LogFileSink) Write ¶
func (s *LogFileSink) Write(event any) error
Write writes a one-line summary of the event.
type Sink ¶
type Sink interface {
// Write records a single event. Returning an error is informational;
// the calling fan-out will log it but not stop processing.
Write(event any) error
// Close releases any resources owned by the sink.
Close() error
}
Sink is anything that can record a loop event. Implementations must be safe for concurrent use and must never block the caller longer than strictly necessary.
type WebhookSink ¶
type WebhookSink struct {
// contains filtered or unexported fields
}
WebhookSink POSTs each envelope as JSON to the configured URL. It uses a single in-flight goroutine guarded by mu so events are delivered in order without blocking the caller's goroutine for longer than the HTTP round-trip.
func NewWebhookSink ¶
func NewWebhookSink(url string, timeout time.Duration) *WebhookSink
NewWebhookSink configures a sink that POSTs envelopes to url. timeout caps a single delivery; <=0 selects 5 seconds.
func (*WebhookSink) Close ¶
func (s *WebhookSink) Close() error
Close is a no-op; the http.Client is reused safely.
func (*WebhookSink) Write ¶
func (s *WebhookSink) Write(event any) error
Write delivers one envelope. Errors are returned but do not stop the loop; the FanOut records them.