diff options
author | Keuin <[email protected]> | 2024-03-09 20:19:35 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2024-03-09 20:20:20 +0800 |
commit | b933083d20b3db4a3d6a8134efe312eb6ff3d8e2 (patch) | |
tree | 2a86151c77b1eed1596b5f50ce824659e3c1fc22 /protocol/messages.go |
Diffstat (limited to 'protocol/messages.go')
-rw-r--r-- | protocol/messages.go | 29 |
1 files changed, 29 insertions, 0 deletions
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"` +} |