eventsink

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: MIT Imports: 10 Imported by: 0

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

func (f *FanOut) Add(s Sink)

Add registers a sink. Nil sinks are ignored so callers can pass New*Sink results directly without nil-checking.

func (*FanOut) Close

func (f *FanOut) Close() error

Close closes every sink and returns the first error encountered.

func (*FanOut) Errors

func (f *FanOut) Errors() []error

Errors returns a snapshot of all sink errors observed so far.

func (*FanOut) Write

func (f *FanOut) Write(event any)

Write sends the event to every sink, collecting any errors.

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

func NewJSONFileSink(path string) (*JSONSink, error)

NewJSONFileSink opens path for writing (truncating) and returns a sink that closes the file on Close.

func NewJSONSink

func NewJSONSink(w io.Writer) *JSONSink

NewJSONSink wraps an existing writer (e.g. os.Stdout) as a sink. The writer is not closed on Close.

func (*JSONSink) Close

func (s *JSONSink) Close() error

Close closes the underlying file (if any).

func (*JSONSink) Write

func (s *JSONSink) Write(event any) error

Write encodes one envelope on its own line.

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

func (s *LogFileSink) Close() error

Close closes the underlying file.

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.

Jump to

Keyboard shortcuts

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