feedkit: split the former maximumdirect.net/weatherd project in two.
feedkit now contains a reusable core, while weatherfeeder is a concrete implementation that includes weather-specific functions.
This commit is contained in:
36
sinks/stdout.go
Normal file
36
sinks/stdout.go
Normal file
@@ -0,0 +1,36 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user