Retire unused module and forecast compatibility exports

This commit is contained in:
2026-08-13 04:15:42 +00:00
parent c3ebf06bd5
commit cd7b9aef2b
11 changed files with 36 additions and 75 deletions

View File

@@ -6,7 +6,7 @@ import (
"fmt"
)
const SnapshotSchemaVersion = "weatherreporter.modules.v1"
const snapshotSchemaVersion = "weatherreporter.modules.v1"
type ID string
@@ -55,16 +55,16 @@ func (o Output) DataPackageValue() any {
func NewSnapshot(outputs []Output) (Snapshot, error) {
snapshot := Snapshot{
SchemaVersion: SnapshotSchemaVersion,
SchemaVersion: snapshotSchemaVersion,
Outputs: append([]Output(nil), outputs...),
}
if err := snapshot.Validate(); err != nil {
if err := snapshot.validate(); err != nil {
return Snapshot{}, err
}
return snapshot, nil
}
func (s Snapshot) Validate() error {
func (s Snapshot) validate() error {
if s.SchemaVersion == "" {
return fmt.Errorf("schemaVersion is required")
}
@@ -89,29 +89,22 @@ func (s Snapshot) Validate() error {
return nil
}
func (s Snapshot) LookupStanza(name string) (Output, bool) {
for _, output := range s.Outputs {
if output.StanzaName == name {
return output, true
}
}
return Output{}, false
}
func StanzaValue[T any](s Snapshot, name string) (T, bool, error) {
var zero T
output, ok := s.LookupStanza(name)
if !ok {
return zero, false, nil
for _, output := range s.Outputs {
if output.StanzaName != name {
continue
}
data, err := json.Marshal(output.Value)
if err != nil {
return zero, true, fmt.Errorf("marshal stanza %q: %w", name, err)
}
if err := json.Unmarshal(data, &zero); err != nil {
return zero, true, fmt.Errorf("decode stanza %q: %w", name, err)
}
return zero, true, nil
}
data, err := json.Marshal(output.Value)
if err != nil {
return zero, true, fmt.Errorf("marshal stanza %q: %w", name, err)
}
if err := json.Unmarshal(data, &zero); err != nil {
return zero, true, fmt.Errorf("decode stanza %q: %w", name, err)
}
return zero, true, nil
return zero, false, nil
}
type MissingDataBehavior string