From b933083d20b3db4a3d6a8134efe312eb6ff3d8e2 Mon Sep 17 00:00:00 2001 From: Keuin Date: Sat, 9 Mar 2024 20:19:35 +0800 Subject: initial version --- protocol/messages.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 protocol/messages.go (limited to 'protocol/messages.go') diff --git a/protocol/messages.go b/protocol/messages.go new file mode 100644 index 0000000..d8f5697 --- /dev/null +++ b/protocol/messages.go @@ -0,0 +1,29 @@ +package protocol + +import ( + "encoding/json" + "time" +) + +type TimeStamp time.Time + +func (t *TimeStamp) UnmarshalJSON(data []byte) error { + var ts int64 + err := json.Unmarshal(data, &ts) + if err != nil { + return err + } + *t = TimeStamp(time.UnixMilli(ts)) + return nil +} + +func (t TimeStamp) MarshalJSON() ([]byte, error) { + return json.Marshal(time.Time(t).UnixMilli()) +} + +type Observation struct { + Time TimeStamp `json:"time"` + Target Target `json:"target"` + Online bool `json:"online"` + Latency uint32 `json:"latency"` +} -- cgit v1.2.3