MCPcopy Create free account
hub / github.com/buggregator/server / UnmarshalJSON

Method UnmarshalJSON

modules/sentry/types.go:17–40  ·  view source on GitHub ↗
(data []byte)

Source from the content-addressed store, hash-verified

15}
16
17func (t *FlexibleTS) UnmarshalJSON(data []byte) error {
18 // Try as number first (v3/v4: 1774960590.323397).
19 var num json.Number
20 if json.Unmarshal(data, &num) == nil {
21 t.value = num
22 return nil
23 }
24
25 // Try as quoted string (v2: "2026-03-31T12:44:44Z").
26 var s string
27 if json.Unmarshal(data, &s) == nil {
28 // Convert ISO 8601 to epoch seconds for uniform downstream handling.
29 if parsed, err := time.Parse(time.RFC3339, s); err == nil {
30 epoch := float64(parsed.UnixNano()) / 1e9
31 t.value = json.Number(strconv.FormatFloat(epoch, 'f', 6, 64))
32 return nil
33 }
34 // Unrecognized string — store as-is.
35 t.value = json.Number(s)
36 return nil
37 }
38
39 return fmt.Errorf("FlexibleTS: cannot unmarshal %s", string(data))
40}
41
42// Number returns the underlying json.Number for use with parseTimestamp.
43func (t FlexibleTS) Number() json.Number { return t.value }

Callers

nothing calls this directly

Calls 2

ParseMethod · 0.80
NumberMethod · 0.80

Tested by

no test coverage detected