fields

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2022 License: Apache-2.0 Imports: 13 Imported by: 2

Documentation

Overview

Package fields define field types for defining JSON views and models.

Index

Constants

View Source
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

type Annotations map[string]string

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 (b Base64) MarshalText() ([]byte, error)

func (Base64) String

func (b Base64) String() string

func (*Base64) UnmarshalText

func (b *Base64) UnmarshalText(data []byte) error

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

type EnumValues map[int]string

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

type FixedDuration struct {
	time.Duration
}

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

type Labels map[string][]string

func (*Labels) Add

func (l *Labels) Add(key string, value string)

Add adds the specified value to the relevant key if it's not already present. The resulting values is a sorted array.

func (Labels) Clone

func (l Labels) Clone() Labels

Clone returns a deep clone of the labels structure.

func (Labels) Get

func (l Labels) Get(key string) []string

Get returns all values for the given key or nil.

func (Labels) MarshalJSON

func (l Labels) MarshalJSON() ([]byte, error)

func (*Labels) Remove

func (l *Labels) Remove(key string, value string)

Remove removes the specified value from the relevant key. If there are no values left for the key, the key is deleted.

func (*Labels) Set

func (l *Labels) Set(key string, values []string)

Set replace the set of values at the given location. Any provided duplicates are automatically removed. If there is no values, the key is deleted.

type Number

type Number float64

Number is a float64 value that JSON encodes the IEEE 754 "not-a-number" value to 'null'.

func (Number) Float64

func (f Number) Float64() float64

func (Number) IsNaN

func (f Number) IsNaN() bool

func (Number) MarshalJSON

func (f Number) MarshalJSON() ([]byte, error)

func (*Number) UnmarshalJSON

func (f *Number) UnmarshalJSON(data []byte) error

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

func AsTimestamp(t time.Time) Timestamp

AsTimestamp converts a time.Time to Timestamp.

func (Timestamp) Add

func (ts Timestamp) Add(d time.Duration) Timestamp

Add adds the fixed duration to the time-stamp.

func (Timestamp) MarshalText

func (ts Timestamp) MarshalText() ([]byte, error)

func (Timestamp) Sub

func (ts Timestamp) Sub(ts2 Timestamp) time.Duration

Sub returns the differences between ts and ts2 as a fixed duration.

func (Timestamp) Time

func (ts Timestamp) Time() time.Time

Time returns the Timestamp as time.Time.

func (Timestamp) Truncate

func (ts Timestamp) Truncate(d time.Duration) Timestamp

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.

func (*Timestamp) UnmarshalText

func (ts *Timestamp) UnmarshalText(data []byte) error

Jump to

Keyboard shortcuts

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