types

package
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BigFloatUnquoted

type BigFloatUnquoted struct {
	*big.Float
}

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

type UnixTime struct {
	time.Time
}

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

func (u UnixTime) MarshalJSON() ([]byte, error)

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

func (u UnixTime) String() string

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

func (u *UnixTime) UnmarshalJSON(b []byte) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL