Handle db connection response on the backend

This commit is contained in:
Alexander Zobnin
2021-08-04 18:07:38 +03:00
parent 848ea8a9a0
commit e12b8cbefb
10 changed files with 233 additions and 33 deletions

View File

@@ -1,6 +1,7 @@
package timeseries
import (
"encoding/json"
"time"
"github.com/alexanderzobnin/grafana-zabbix/pkg/zabbix"
@@ -11,6 +12,22 @@ type TimePoint struct {
Value *float64
}
func (p *TimePoint) UnmarshalJSON(data []byte) error {
point := &struct {
Time int64
Value *float64
}{}
if err := json.Unmarshal(data, &point); err != nil {
return err
}
p.Value = point.Value
p.Time = time.Unix(point.Time, 0)
return nil
}
type TimeSeries []TimePoint
func NewTimeSeries() TimeSeries {