Documentation
¶
Overview ¶
Package fields define field types for defining JSON views and models.
Index ¶
- Constants
- type Annotations
- type Base64
- type Base64NullZero
- type EnumValues
- type FixedDuration
- type Hexadecimal
- type HexadecimalNullZero
- type Labels
- type Number
- type Timestamp
- func (ts Timestamp) Add(d time.Duration) Timestamp
- func (ts Timestamp) MarshalText() ([]byte, error)
- func (ts Timestamp) Sub(ts2 Timestamp) time.Duration
- func (ts Timestamp) Time() time.Time
- func (ts Timestamp) Truncate(d time.Duration) Timestamp
- func (ts *Timestamp) UnmarshalText(data []byte) error
Constants ¶
const (
ErrBadFixedDuration strErr = "must be RFC 3339 duration in range week to fraction"
)
Parsing errors.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Annotations ¶
func (Annotations) Get ¶
func (m Annotations) Get(key string) string
Get returns the value for the given key or an empty string.
func (*Annotations) Set ¶
func (m *Annotations) Set(key, value string)
Set sets the given annotation value to key.
type Base64 ¶
type Base64 []byte
Base64 wraps a slice of bytes in order for it to be represented as an RF 4648 raw URL encoded string (i.e without padding). It's more compact than Hexadecimal.
func (Base64) MarshalText ¶
func (*Base64) UnmarshalText ¶
type Base64NullZero ¶
type Base64NullZero Base64
Base64NullZero is a variant of Base64 which zero value JSON-encodes to null.
func (Base64NullZero) MarshalJSON ¶
func (zn Base64NullZero) MarshalJSON() ([]byte, error)
func (*Base64NullZero) UnmarshalJSON ¶
func (zn *Base64NullZero) UnmarshalJSON(data []byte) error
type EnumValues ¶
EnumValues maps integer Items values to strings.
func (EnumValues) Clone ¶
func (e EnumValues) Clone() EnumValues
Clone returns a deep clone of the enums structure.
func (EnumValues) MarshalJSON ¶
func (e EnumValues) MarshalJSON() ([]byte, error)
type FixedDuration ¶
FixedDuration wraps a time.Duration so that it's JSON encoded as an RFC 3339 duration string. The zero-value is encoded as null.
func AsFixedDuration ¶
func AsFixedDuration(d time.Duration) FixedDuration
AsFixedDuration converts d to a FixedDuration.
func ParseFixedDuration ¶
func ParseFixedDuration(s string) (FixedDuration, error)
ParseFixedDuration parses a RFC 3339 string accepting weeks, days, hours, minute, seconds and fractions.
func (FixedDuration) MarshalJSON ¶
func (d FixedDuration) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (FixedDuration) String ¶
func (d FixedDuration) String() string
func (*FixedDuration) UnmarshalJSON ¶
func (d *FixedDuration) UnmarshalJSON(b []byte) error
UnmarshalJSON implements json.Unmarshaler.
type Hexadecimal ¶
type Hexadecimal []byte
Hexadecimal wraps a slice of bytes in order for it to be represented as a hexadecimal string when encoded. It is less compact that Base64 encoding.
func (Hexadecimal) MarshalText ¶
func (b Hexadecimal) MarshalText() ([]byte, error)
func (Hexadecimal) String ¶
func (b Hexadecimal) String() string
func (*Hexadecimal) UnmarshalText ¶
func (b *Hexadecimal) UnmarshalText(data []byte) error
type HexadecimalNullZero ¶
type HexadecimalNullZero Hexadecimal
HexadecimalNullZero is a variant of Hexadecimal which zero value JSON-encodes to null.
func (HexadecimalNullZero) MarshalJSON ¶
func (zn HexadecimalNullZero) MarshalJSON() ([]byte, error)
func (*HexadecimalNullZero) UnmarshalJSON ¶
func (zn *HexadecimalNullZero) UnmarshalJSON(data []byte) error
type Labels ¶
func (*Labels) Add ¶
Add adds the specified value to the relevant key if it's not already present. The resulting values is a sorted array.
func (Labels) MarshalJSON ¶
type Number ¶
type Number float64
Number is a float64 value that JSON encodes the IEEE 754 "not-a-number" value to 'null'.
func (Number) MarshalJSON ¶
func (*Number) UnmarshalJSON ¶
type Timestamp ¶
type Timestamp int64
Timestamp provides a hashable and comparable alternative to time.Time, stored as microseconds since the epoch.
const ( // OriginTime defines midnight of the first Monday of year 2000 in the // UTC time-zone (2000-01-03T00:00:00Z) as microseconds since the epoch. OriginTime Timestamp = 946857600000000 )
func AsTimestamp ¶
AsTimestamp converts a time.Time to Timestamp.
func (Timestamp) MarshalText ¶
func (Timestamp) Truncate ¶
Truncate returns the result of rounding ts down to a multiple of d (since OriginTime). Note that this is not fully equivalent to using Truncate on the time.Time type, as we are deliberately using a different origin.