feedkit now contains a reusable core, while weatherfeeder is a concrete implementation that includes weather-specific functions.
37 lines
866 B
Go
37 lines
866 B
Go
package sinks
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"gitea.maximumdirect.net/ejr/feedkit/event"
|
|
)
|
|
|
|
type StdoutSink struct{ name string }
|
|
|
|
func NewStdoutSink(name string) *StdoutSink {
|
|
return &StdoutSink{name: name}
|
|
}
|
|
|
|
func (s *StdoutSink) Name() string { return s.name }
|
|
|
|
func (s *StdoutSink) Consume(ctx context.Context, e event.Event) error {
|
|
_ = ctx
|
|
|
|
// Boundary validation: if something upstream violated invariants,
|
|
// surface it loudly rather than printing partial nonsense.
|
|
if err := e.Validate(); err != nil {
|
|
return fmt.Errorf("stdout sink: invalid event: %w", err)
|
|
}
|
|
|
|
// Generic default: one JSON line per event.
|
|
// This makes stdout useful across all domains and easy to pipe into jq / logs.
|
|
b, err := json.Marshal(e)
|
|
if err != nil {
|
|
return fmt.Errorf("stdout sink: marshal event: %w", err)
|
|
}
|
|
fmt.Println(string(b))
|
|
return nil
|
|
}
|