Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BigFloatUnquoted ¶
BigFloatUnquoted is a wrapper around big.Float to handle JSON marshalling as a string without quotes, as the P1 API expects.
func (BigFloatUnquoted) MarshalJSON ¶
func (b BigFloatUnquoted) MarshalJSON() ([]byte, error)
func (*BigFloatUnquoted) UnmarshalJSON ¶
func (b *BigFloatUnquoted) UnmarshalJSON(p []byte) error
type UnixTime ¶ added in v0.4.0
UnixTime wraps time.Time to support JSON marshaling and unmarshaling using Unix timestamp integers. Times are always stored and returned in UTC. The zero value for UnixTime is equivalent to the Unix epoch (January 1, 1970 00:00:00 UTC).
When unmarshaling, UnixTime accepts:
- Integer Unix timestamps in seconds (e.g., 1609459200)
- Integer Unix timestamps in milliseconds (e.g., 1609459200000)
- Automatically detects milliseconds vs seconds based on magnitude
- null values (results in zero time)
When marshaling, UnixTime produces:
- Integer Unix timestamps in seconds for non-zero times
- null for zero times
Example usage:
type Event struct {
OccurredAt UnixTime `json:"occurred_at"`
}
// Unmarshaling from JSON
jsonData := []byte(`{"occurred_at": 1609459200}`)
var event Event
json.Unmarshal(jsonData, &event)
// Marshaling to JSON
data, _ := json.Marshal(event)
func (UnixTime) MarshalJSON ¶ added in v0.4.0
MarshalJSON implements the json.Marshaler interface. It converts the time to a Unix timestamp integer (seconds since epoch). Zero times are marshaled as null.
func (UnixTime) String ¶ added in v0.4.0
String returns the time formatted in RFC3339 format with UTC timezone. This provides a human-readable representation for logging and debugging.
func (*UnixTime) UnmarshalJSON ¶ added in v0.4.0
UnmarshalJSON implements the json.Unmarshaler interface. It accepts Unix timestamp integers in seconds or milliseconds and converts them to UTC time. Automatically detects milliseconds (values > 1e12) vs seconds. Null values are accepted and result in a zero time value. Negative timestamps are supported for dates before the Unix epoch.