Fix: specific entry unmarshal

This commit is contained in:
Mathieu Lecarme 2022-06-07 15:54:01 +02:00 committed by lperdereau
parent b17711ed99
commit bd28c2c1bc

View file

@ -1,12 +1,31 @@
package loki
import "time"
import (
"encoding/json"
"strconv"
"time"
)
type Entry struct {
Timestamp time.Time
Line string
}
func (e *Entry) UnmarshalJSON(b []byte) error {
var values []string
err := json.Unmarshal(b, &values)
if err != nil {
return err
}
t, err := strconv.Atoi(values[0])
if err != nil {
return err
}
e.Timestamp = time.Unix(int64(t), 0)
e.Line = values[1]
return nil
}
type Stream struct {
Stream map[string]string `json:"stream"`
Entries []Entry `json:"values"`