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:
37
sinks/postgres.go
Normal file
37
sinks/postgres.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package sinks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"gitea.maximumdirect.net/ejr/feedkit/config"
|
||||
"gitea.maximumdirect.net/ejr/feedkit/event"
|
||||
)
|
||||
|
||||
type PostgresSink struct {
|
||||
name string
|
||||
dsn string
|
||||
}
|
||||
|
||||
func NewPostgresSinkFromConfig(cfg config.SinkConfig) (Sink, error) {
|
||||
dsn, err := requireStringParam(cfg, "dsn")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &PostgresSink{name: cfg.Name, dsn: dsn}, nil
|
||||
}
|
||||
|
||||
func (p *PostgresSink) Name() string { return p.name }
|
||||
|
||||
func (p *PostgresSink) 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("rabbitmq sink: invalid event: %w", err)
|
||||
}
|
||||
|
||||
// TODO implement Postgres transaction
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user