Files
weatherfeeder/internal/normalizers/common/finalize.go
Eric Rakestraw 2c1278a70a
All checks were successful
ci/woodpecker/push/build-image Pipeline was successful
Moved generic and broadly useful helper functions upstream into feedkit
2026-03-28 11:30:20 -05:00

24 lines
1023 B
Go

// FILE: ./internal/normalizers/common/finalize.go
package common
import (
"time"
"gitea.maximumdirect.net/ejr/feedkit/event"
fknormalize "gitea.maximumdirect.net/ejr/feedkit/processors/normalize"
)
// Finalize builds the output event envelope by copying the input and applying the
// canonical schema/payload, plus (optionally) EffectiveAt.
//
// Important behavior:
// - ID/Kind/Source/EmittedAt are preserved by copying the input event.
// - EffectiveAt is only overwritten when effectiveAt is non-zero.
// If effectiveAt is zero, any existing in.EffectiveAt is preserved.
// - Payload floats are rounded to a stable wire-friendly precision (see round.go).
func Finalize(in event.Event, outSchema string, outPayload any, effectiveAt time.Time) (*event.Event, error) {
// Enforce stable numeric presentation for weather payloads before delegating to feedkit's
// generic envelope finalizer.
return fknormalize.FinalizeEvent(in, outSchema, RoundFloats(outPayload, DefaultFloatPrecision), effectiveAt)
}