Files
overlord/Overlord-Client/cmd/agent/handlers/extract.go
T

47 lines
814 B
Go
Raw Normal View History

2026-03-05 00:04:26 -06:00
package handlers
import "encoding/json"
func extractTimestamp(v interface{}) int64 {
ts, ok := extractTimestampIfPresent(v)
if !ok {
return 0
}
return ts
}
func extractTimestampIfPresent(v interface{}) (int64, bool) {
2026-03-05 00:04:26 -06:00
switch t := v.(type) {
case uint64:
if t <= uint64(^uint64(0)>>1) {
return int64(t), true
2026-03-05 00:04:26 -06:00
}
return 0, false
2026-03-05 00:04:26 -06:00
case uint32:
return int64(t), true
2026-03-05 00:04:26 -06:00
case uint16:
return int64(t), true
2026-03-05 00:04:26 -06:00
case uint8:
return int64(t), true
2026-03-05 00:04:26 -06:00
case int64:
return t, true
2026-03-05 00:04:26 -06:00
case int32:
return int64(t), true
2026-03-05 00:04:26 -06:00
case int16:
return int64(t), true
2026-03-05 00:04:26 -06:00
case int8:
return int64(t), true
2026-03-05 00:04:26 -06:00
case int:
return int64(t), true
2026-03-05 00:04:26 -06:00
case float64:
return int64(t), true
2026-03-05 00:04:26 -06:00
case float32:
return int64(t), true
2026-03-05 00:04:26 -06:00
case json.Number:
if n, err := t.Int64(); err == nil {
return n, true
2026-03-05 00:04:26 -06:00
}
}
return 0, false
2026-03-05 00:04:26 -06:00
}