Allow to add self to nodes

This commit is contained in:
Ingo Oppermann
2023-05-08 11:39:43 +02:00
parent b8b2990e61
commit ab86b8fd5d
7 changed files with 205 additions and 233 deletions

View File

@@ -1,6 +1,7 @@
package api
import (
"encoding/json"
"fmt"
"time"
@@ -50,6 +51,21 @@ func (v MetricsResponseValue) MarshalJSON() ([]byte, error) {
return []byte(s), nil
}
// MarshalJSON unmarshals a JSON to MetricsResponseValue
func (v *MetricsResponseValue) UnmarshalJSON(data []byte) error {
x := []float64{}
err := json.Unmarshal(data, &x)
if err != nil {
return err
}
v.TS = time.Unix(int64(x[0]), 0)
v.Value = x[1]
return nil
}
type MetricsResponse struct {
Timerange int64 `json:"timerange_sec" format:"int64"`
Interval int64 `json:"interval_sec" format:"int64"`