From 59491201976316a30ffc475dd99b0af02b5e997d Mon Sep 17 00:00:00 2001 From: Petri Hienonen Date: Sun, 4 Jan 2026 11:52:47 +0200 Subject: Both publisher and subscriber --- internal/weather/types.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 internal/weather/types.go (limited to 'internal/weather/types.go') diff --git a/internal/weather/types.go b/internal/weather/types.go new file mode 100644 index 0000000..5563bfa --- /dev/null +++ b/internal/weather/types.go @@ -0,0 +1,44 @@ +package weather + +import ( + "encoding/json" + "math" + "time" +) + +// Observation represents a weather observation from a station +type Observation struct { + Station int `json:"station"` + Parameter string `json:"parameter"` + Time time.Time `json:"time"` + Value *float64 `json:"value,omitempty"` +} + +// ForecastValue represents a weather forecast value +type ForecastValue struct { + Location struct { + Lat float64 `json:"lat"` + Lon float64 `json:"lon"` + } `json:"location"` + Model string `json:"model"` + RunTime time.Time `json:"run_time"` + ForecastTime time.Time `json:"forecast_time"` + Parameter string `json:"parameter"` + Value *float64 `json:"value,omitempty"` +} + +// JSONFloat64 handles NaN values properly in JSON +type JSONFloat64 float64 + +func (f JSONFloat64) MarshalJSON() ([]byte, error) { + if math.IsNaN(float64(f)) { + return []byte("null"), nil + } + return json.Marshal(float64(f)) +} + +// TopicStats tracks message statistics for subscribers +type TopicStats struct { + MessagesReceived map[string]int + LastMessageTime map[string]time.Time +} -- cgit v1.2.3-70-g09d2